diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2022-09-20 11:59:16 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-12 20:03:43 +0000 |
commit | 566094fc629ab1e92afb0cdf191a0e2c685b5c35 (patch) | |
tree | ce172266109cf1c4e81a041e460c6cc7bcd5d50e /server | |
parent | bcfb1cac55137b838da7a93385b20e0e5ed47abb (diff) | |
download | sonarqube-566094fc629ab1e92afb0cdf191a0e2c685b5c35.tar.gz sonarqube-566094fc629ab1e92afb0cdf191a0e2c685b5c35.zip |
SONAR-17352 Refactor component keys to not include branch suffix
Diffstat (limited to 'server')
327 files changed, 2322 insertions, 2095 deletions
diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java index ab5953f13b3..b207dd7e410 100644 --- a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java +++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java @@ -352,14 +352,14 @@ public class CeQueueImpl implements CeQueue { String componentUuid = taskDto.getComponentUuid(); if (component != null) { - builder.setComponent(new CeTask.Component(component.uuid(), component.getDbKey(), component.name())); + builder.setComponent(new CeTask.Component(component.uuid(), component.getKey(), component.name())); } else if (componentUuid != null) { builder.setComponent(new CeTask.Component(componentUuid, null, null)); } String mainComponentUuid = taskDto.getMainComponentUuid(); if (mainComponent != null) { - builder.setMainComponent(new CeTask.Component(mainComponent.uuid(), mainComponent.getDbKey(), mainComponent.name())); + builder.setMainComponent(new CeTask.Component(mainComponent.uuid(), mainComponent.getKey(), mainComponent.name())); } else if (mainComponentUuid != null) { builder.setMainComponent(new CeTask.Component(mainComponentUuid, null, null)); } diff --git a/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java b/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java index 8a7e205bd3c..7ea2ba50baf 100644 --- a/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java +++ b/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java @@ -507,7 +507,7 @@ public class CeQueueImplTest { if (componentDto != null) { CeTask.Component component = task.getComponent().get(); assertThat(component.getUuid()).isEqualTo(componentDto.uuid()); - assertThat(component.getKey()).contains(componentDto.getDbKey()); + assertThat(component.getKey()).contains(componentDto.getKey()); assertThat(component.getName()).contains(componentDto.name()); } else if (taskSubmit.getComponent().isPresent()) { assertThat(task.getComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getUuid(), null, null)); @@ -517,7 +517,7 @@ public class CeQueueImplTest { if (mainComponentDto != null) { CeTask.Component component = task.getMainComponent().get(); assertThat(component.getUuid()).isEqualTo(mainComponentDto.uuid()); - assertThat(component.getKey()).contains(mainComponentDto.getDbKey()); + assertThat(component.getKey()).contains(mainComponentDto.getKey()); assertThat(component.getName()).contains(mainComponentDto.name()); } else if (taskSubmit.getComponent().isPresent()) { assertThat(task.getMainComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getMainComponentUuid(), null, null)); 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 @@ -76,13 +76,6 @@ public interface Component { String getUuid(); /** - * Returns the component key <b>as defined in database</b> - * 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 * If new branch feature is used, the key will not 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; @@ -85,11 +83,6 @@ public class ComponentImpl implements Component { } @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. * <p> @@ -72,7 +70,6 @@ public class ComponentTreeBuilder { public ComponentTreeBuilder( ComponentKeyGenerator keyGenerator, - ComponentKeyGenerator publicKeyGenerator, UnaryOperator<String> uuidSupplier, Function<Integer, ScannerReport.Component> 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<Component> 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<Component> 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<T> 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<T> 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<ComponentDto> components = dbClient.componentDao().selectByProjectUuid(referenceBranchUuid, dbSession); + List<ComponentDto> 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<KeyWithUuidDto> 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<KeyWithUuidDto> 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<Duplication> getDuplications(Component file) { checkFileComponentArgument(file); - Collection<Duplication> res = this.duplications.asMap().get(file.getDbKey()); + Collection<Duplication> 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<String, String> pathByModuleKey = reportModulesPath.get(); // Migrate issues that were previously on modules or directories to the root project - Map<String, ComponentDto> modulesByUuid = dbClient.componentDao().selectProjectAndModulesFromProjectKey(dbSession, component.getDbKey(), true) + Map<String, ComponentDto> modulesByUuid = dbClient.componentDao().selectProjectAndModulesFromProjectKey(dbSession, component.getKey(), true) .stream().collect(Collectors.toMap(ComponentDto::uuid, Function.identity())); List<ComponentDto> 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<SiblingIssue> loadCandidateSiblingIssuesForMerging(Component component) { - String componentKey = ComponentDto.removeBranchAndPullRequestFromKey(component.getDbKey()); + String componentKey = ComponentDto.removeBranchAndPullRequestFromKey(component.getKey()); Set<String> 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<ComponentDto> targetComponents = dbClient.componentDao().selectByProjectUuid(sourceBranchUuid, dbSession); + List<ComponentDto> 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<String, String> 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<BranchDto> 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<ComponentDto> targetComponents = dbClient.componentDao().selectByProjectUuid(targetBranchUuid, dbSession); + List<ComponentDto> 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<DefaultIssue> 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<DefaultIssue> 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<DefaultIssue> 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<T> 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<T> 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<ComponentDto> components = dbClient.componentDao().selectByProjectUuid(referenceBranchUuid, dbSession); + List<ComponentDto> 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<ScmInfo> 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<MovedFilesRepository.OriginalFile> 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<SnapshotDto> 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<Block> duplicatedBlocks = dtos.stream().map(DtoToBlock.INSTANCE).collect(Collectors.toList()); - Collection<Block> originBlocks = cpdTextBlocks.stream().map(new CpdTextBlockToBlock(file.getDbKey())).collect(Collectors.toList()); - LOGGER.trace("Found {} duplicated cpd blocks on file {}", duplicatedBlocks.size(), file.getDbKey()); + Collection<Block> 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<String, ComponentDto> 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<ComponentDtoHolder> 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<ComponentDtoHolder> 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<ComponentUpdateDto> 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<Duplication> 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<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getDbKey()); - Map<String, ComponentDto> baseModulesByKey = baseModules.stream().collect(Collectors.toMap(ComponentDto::getDbKey, x -> x)); + List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey()); + Map<String, ComponentDto> 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<BranchDto> 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<ComponentDto> 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<Integer> { super(maxDepth, order, new SimpleStackElementFactory<Integer>() { @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<Integer> { } private static PathAwareCallRecord viewsCallRecord(Component component, Path<Integer> 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<String> UUID_SUPPLIER = (componentKey) -> componentKey + "_uuid"; private static final EnumSet<ScannerReport.Component.ComponentType> 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<String, Component> 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<String, Component> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<Integer>() { @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<DefaultIssue> 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<DefaultIssue> 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<DefaultIssue> 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<DefaultIssue> 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<DefaultIssue> 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<DefaultIssue> 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<DefaultIssue> 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<DefaultIssue> 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<String, Component> 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<Integer, Component> 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<Integer, Block> 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<ComponentDto> 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 <T> Consumer<T> 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<DefaultIssue> 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<BranchDto> 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<BranchDto> 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,7 +94,7 @@ 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())); } @@ -105,14 +102,6 @@ public class ReportComponent implements Component { } @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<Map.Entry<InternalKey, Measure>> { - private final Metric metric; - - public MatchMetric(Metric metric) { - this.metric = metric; - } - - @Override - public boolean apply(@Nonnull Map.Entry<InternalKey, Measure> input) { - return input.getKey().getMetricKey().equals(metric.getKey()); - } - } - - private enum ToMeasure implements Function<Map.Entry<InternalKey, Measure>, Measure> { - INSTANCE; - - @Nullable - @Override - public Measure apply(@Nonnull Map.Entry<InternalKey, Measure> input) { - return input.getValue(); - } - } - } diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java index 935948712d7..05b04d9ac2f 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java @@ -351,8 +351,8 @@ public class InternalCeQueueImplTest { assertThat(peek).isPresent(); assertThat(peek.get().getUuid()).isEqualTo(task.getUuid()); assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT); - assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.uuid(), branch.getDbKey(), branch.name())); - assertThat(peek.get().getMainComponent()).contains(new CeTask.Component(project.uuid(), project.getDbKey(), project.name())); + assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.uuid(), branch.getKey(), branch.name())); + assertThat(peek.get().getMainComponent()).contains(new CeTask.Component(project.uuid(), project.getKey(), project.name())); // no more pending tasks peek = underTest.peek(WORKER_UUID_2, true); @@ -608,7 +608,7 @@ public class InternalCeQueueImplTest { if (componentDto != null) { CeTask.Component component = task.getComponent().get(); assertThat(component.getUuid()).isEqualTo(componentDto.uuid()); - assertThat(component.getKey()).contains(componentDto.getDbKey()); + assertThat(component.getKey()).contains(componentDto.getKey()); assertThat(component.getName()).contains(componentDto.name()); } else if (taskSubmit.getComponent().isPresent()) { assertThat(task.getComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getUuid(), null, null)); @@ -644,7 +644,7 @@ public class InternalCeQueueImplTest { } private ComponentDto newProjectDto(String uuid) { - return ComponentTesting.newPublicProjectDto(uuid).setName("name_" + uuid).setDbKey("key_" + uuid); + return ComponentTesting.newPublicProjectDto(uuid).setName("name_" + uuid).setKey("key_" + uuid); } private CeTask submit(String reportType, ComponentDto componentDto) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index 14da008f50e..515fd70c61a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -62,7 +62,7 @@ import org.sonar.db.component.ResourceDto; import org.sonar.db.component.ScrapAnalysisPropertyDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.component.SnapshotMapper; -import org.sonar.db.component.UuidWithProjectUuidDto; +import org.sonar.db.component.UuidWithBranchUuidDto; import org.sonar.db.component.ViewsSnapshotDto; import org.sonar.db.duplication.DuplicationMapper; import org.sonar.db.duplication.DuplicationUnitDto; @@ -243,7 +243,7 @@ public class MyBatis { confBuilder.loadAlias("UserTelemetry", UserTelemetryDto.class); confBuilder.loadAlias("UserToken", UserTokenDto.class); confBuilder.loadAlias("UserTokenCount", UserTokenCount.class); - confBuilder.loadAlias("UuidWithProjectUuid", UuidWithProjectUuidDto.class); + confBuilder.loadAlias("UuidWithBranchUuid", UuidWithBranchUuidDto.class); confBuilder.loadAlias("ViewsSnapshot", ViewsSnapshotDto.class); confExtensions.forEach(ext -> ext.loadAliases(confBuilder::loadAlias)); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java index 38cca4e8201..f655c175cfd 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java @@ -92,7 +92,7 @@ public class BranchDao implements Dao { public Collection<BranchDto> selectByComponent(DbSession dbSession, ComponentDto component) { String projectUuid = component.getMainBranchProjectUuid(); if (projectUuid == null) { - projectUuid = component.projectUuid(); + projectUuid = component.branchUuid(); } return mapper(dbSession).selectByProjectUuid(projectUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index b11d2801afd..d843733d1ff 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -23,6 +23,7 @@ import com.google.common.collect.Ordering; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -32,6 +33,7 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nullable; +import org.apache.commons.lang.StringUtils; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import org.sonar.api.resources.Qualifiers; @@ -44,14 +46,10 @@ import org.sonar.db.audit.model.ComponentNewValue; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Collections.emptyList; -import static org.sonar.core.util.stream.MoreCollectors.toList; -import static org.sonar.core.util.stream.MoreCollectors.toSet; import static org.sonar.db.DatabaseUtils.checkThatNotTooManyConditions; import static org.sonar.db.DatabaseUtils.executeLargeInputs; import static org.sonar.db.DatabaseUtils.executeLargeInputsIntoSet; import static org.sonar.db.DatabaseUtils.executeLargeUpdates; -import static org.sonar.db.component.ComponentDto.generateBranchKey; -import static org.sonar.db.component.ComponentDto.generatePullRequestKey; public class ComponentDao implements Dao { private final AuditPersister auditPersister; @@ -85,11 +83,7 @@ public class ComponentDao implements Dao { } public ComponentDto selectOrFailByUuid(DbSession session, String uuid) { - Optional<ComponentDto> componentDto = selectByUuid(session, uuid); - if (!componentDto.isPresent()) { - throw new RowNotFoundException(String.format("Component with uuid '%s' not found", uuid)); - } - return componentDto.get(); + return selectByUuid(session, uuid).orElseThrow(() -> new RowNotFoundException(String.format("Component with uuid '%s' not found", uuid))); } /** @@ -156,8 +150,8 @@ public class ComponentDao implements Dao { return mapper(session).selectComponentsFromProjectKeyAndScope(projectKey, Scopes.PROJECT, excludeDisabled); } - public int countEnabledModulesByProjectUuid(DbSession session, String projectUuid) { - return mapper(session).countEnabledModulesByProjectUuid(projectUuid); + public int countEnabledModulesByBranchUuid(DbSession session, String branchUuid) { + return mapper(session).countEnabledModulesByBranchUuid(branchUuid); } public List<ComponentDto> selectEnabledModulesFromProjectKey(DbSession session, String projectKey) { @@ -169,30 +163,45 @@ public class ComponentDao implements Dao { } public List<ComponentDto> selectByKeysAndBranch(DbSession session, Collection<String> keys, String branch) { - List<String> dbKeys = keys.stream().map(k -> generateBranchKey(k, branch)).collect(toList()); - List<String> allKeys = Stream.of(keys, dbKeys).flatMap(Collection::stream).collect(toList()); - return executeLargeInputs(allKeys, subKeys -> mapper(session).selectByKeysAndBranch(subKeys, branch)); - } - - /** - * Return list of components that will will mix main and branch components. - * Please note that a project can only appear once in the list, it's not possible to ask for many branches on same project with this method. - */ - public List<ComponentDto> selectByKeysAndBranches(DbSession session, Map<String, String> branchesByKey) { - Set<String> dbKeys = branchesByKey.entrySet().stream() - .map(entry -> generateBranchKey(entry.getKey(), entry.getValue())) - .collect(toSet()); - return selectByDbKeys(session, dbKeys); - } - - public List<ComponentDto> selectByDbKeys(DbSession session, Set<String> dbKeys) { - return executeLargeInputs(dbKeys, subKeys -> mapper(session).selectByDbKeys(subKeys)); + return executeLargeInputs(keys, subKeys -> mapper(session).selectByKeysAndBranch(subKeys, branch)); } public List<ComponentDto> selectByKeysAndPullRequest(DbSession session, Collection<String> keys, String pullRequestId) { - List<String> dbKeys = keys.stream().map(k -> generatePullRequestKey(k, pullRequestId)).collect(toList()); - List<String> allKeys = Stream.of(keys, dbKeys).flatMap(Collection::stream).collect(toList()); - return executeLargeInputs(allKeys, subKeys -> mapper(session).selectByKeysAndBranch(subKeys, pullRequestId)); + return executeLargeInputs(keys, subKeys -> mapper(session).selectByKeysAndBranch(subKeys, pullRequestId)); + } + + public List<ComponentDto> selectByDbKeys(DbSession session, Collection<String> dbKeys) { + Map<String, List<String>> keyByBranchKey = new HashMap<>(); + Map<String, List<String>> keyByPrKey = new HashMap<>(); + List<String> mainBranchKeys = new LinkedList<>(); + + for (String dbKey : dbKeys) { + String branchKey = StringUtils.substringAfterLast(dbKey, ComponentDto.BRANCH_KEY_SEPARATOR); + if (!StringUtils.isEmpty(branchKey)) { + keyByBranchKey.computeIfAbsent(branchKey, b -> new LinkedList<>()) + .add(StringUtils.substringBeforeLast(dbKey, ComponentDto.BRANCH_KEY_SEPARATOR)); + continue; + } + + String prKey = StringUtils.substringAfterLast(dbKey, ComponentDto.PULL_REQUEST_SEPARATOR); + if (!StringUtils.isEmpty(prKey)) { + keyByPrKey.computeIfAbsent(prKey, b -> new LinkedList<>()) + .add(StringUtils.substringBeforeLast(dbKey, ComponentDto.PULL_REQUEST_SEPARATOR)); + continue; + } + + mainBranchKeys.add(dbKey); + } + + List<ComponentDto> components = new LinkedList<>(); + for (Map.Entry<String, List<String>> e : keyByBranchKey.entrySet()) { + components.addAll(selectByKeysAndBranch(session, e.getValue(), e.getKey())); + } + for (Map.Entry<String, List<String>> e : keyByPrKey.entrySet()) { + components.addAll(selectByKeysAndPullRequest(session, e.getValue(), e.getKey())); + } + components.addAll(selectByKeys(session, mainBranchKeys)); + return components; } /** @@ -230,11 +239,7 @@ public class ComponentDao implements Dao { } public ComponentDto selectOrFailByKey(DbSession session, String key) { - Optional<ComponentDto> component = selectByKey(session, key); - if (!component.isPresent()) { - throw new RowNotFoundException(String.format("Component key '%s' not found", key)); - } - return component.get(); + return selectByKey(session, key).orElseThrow(() -> new RowNotFoundException(String.format("Component key '%s' not found", key))); } public Optional<ComponentDto> selectByKey(DbSession session, String key) { @@ -246,14 +251,14 @@ public class ComponentDao implements Dao { } public Optional<ComponentDto> selectByKeyAndBranch(DbSession session, String key, String branch) { - return Optional.ofNullable(mapper(session).selectBranchByKeyAndBranchKey(key, generateBranchKey(key, branch), branch)); + return Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, branch)); } public Optional<ComponentDto> selectByKeyAndPullRequest(DbSession session, String key, String pullRequestId) { - return Optional.ofNullable(mapper(session).selectPrByKeyAndBranchKey(key, generatePullRequestKey(key, pullRequestId), pullRequestId)); + return Optional.ofNullable(mapper(session).selectByKeyAndPrKey(key, pullRequestId)); } - public List<UuidWithProjectUuidDto> selectAllViewsAndSubViews(DbSession session) { + public List<UuidWithBranchUuidDto> selectAllViewsAndSubViews(DbSession session) { return mapper(session).selectUuidsForQualifiers(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.SUBVIEW); } @@ -295,12 +300,12 @@ public class ComponentDao implements Dao { } /** - * Retrieves all components with a specific root project Uuid, no other filtering is done by this method. + * Retrieves all components with a specific branch UUID, no other filtering is done by this method. * <p> * Used by Views plugin */ - public List<ComponentDto> selectByProjectUuid(String projectUuid, DbSession dbSession) { - return mapper(dbSession).selectByProjectUuid(projectUuid); + public List<ComponentDto> selectByBranchUuid(String branchUuid, DbSession dbSession) { + return mapper(dbSession).selectByBranchUuid(branchUuid); } /** @@ -340,8 +345,8 @@ public class ComponentDao implements Dao { * Scroll all <strong>enabled</strong> files of the specified project (same project_uuid) in no specific order with * 'SOURCE' source and a non null path. */ - public void scrollAllFilesForFileMove(DbSession session, String projectUuid, ResultHandler<FileMoveRowDto> handler) { - mapper(session).scrollAllFilesForFileMove(projectUuid, handler); + public void scrollAllFilesForFileMove(DbSession session, String branchUuid, ResultHandler<FileMoveRowDto> handler) { + mapper(session).scrollAllFilesForFileMove(branchUuid, handler); } public void insert(DbSession session, ComponentDto item) { @@ -373,23 +378,23 @@ public class ComponentDao implements Dao { executeLargeUpdates(uuids, mapper(session)::updateBEnabledToFalse); } - public void applyBChangesForRootComponentUuid(DbSession session, String projectUuid) { - mapper(session).applyBChangesForRootComponentUuid(projectUuid); + public void applyBChangesForRootComponentUuid(DbSession session, String branchUuid) { + mapper(session).applyBChangesForRootComponentUuid(branchUuid); } - public void resetBChangedForRootComponentUuid(DbSession session, String projectUuid) { - mapper(session).resetBChangedForRootComponentUuid(projectUuid); + public void resetBChangedForRootComponentUuid(DbSession session, String branchUuid) { + mapper(session).resetBChangedForRootComponentUuid(branchUuid); } - public void setPrivateForRootComponentUuidWithoutAudit(DbSession session, String projectUuid, boolean isPrivate) { - mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate); + public void setPrivateForRootComponentUuidWithoutAudit(DbSession session, String branchUuid, boolean isPrivate) { + mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate); } - public void setPrivateForRootComponentUuid(DbSession session, String projectUuid, boolean isPrivate, + public void setPrivateForRootComponentUuid(DbSession session, String branchUuid, boolean isPrivate, @Nullable String qualifier, String componentKey, String componentName) { - ComponentNewValue componentNewValue = new ComponentNewValue(projectUuid, componentName, componentKey, isPrivate, qualifier); + ComponentNewValue componentNewValue = new ComponentNewValue(branchUuid, componentName, componentKey, isPrivate, qualifier); auditPersister.updateComponentVisibility(session, componentNewValue); - mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate); + mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate); } private static void checkThatNotTooManyComponents(ComponentQuery query) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java index a3818109278..cb17c2a859e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java @@ -24,7 +24,6 @@ import com.google.common.base.Strings; import java.util.Date; import java.util.List; import java.util.Objects; -import java.util.regex.Pattern; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.builder.ToStringBuilder; @@ -47,7 +46,6 @@ public class ComponentDto { public static final String BRANCH_KEY_SEPARATOR = ":BRANCH:"; public static final String PULL_REQUEST_SEPARATOR = ":PULL_REQUEST:"; - private static final Splitter BRANCH_OR_PULL_REQUEST_SPLITTER = Splitter.on(Pattern.compile(BRANCH_KEY_SEPARATOR + "|" + PULL_REQUEST_SEPARATOR)); private static final Splitter BRANCH_KEY_SPLITTER = Splitter.on(BRANCH_KEY_SEPARATOR); private static final Splitter PULL_REQUEST_SPLITTER = Splitter.on(PULL_REQUEST_SEPARATOR); @@ -93,7 +91,7 @@ public class ComponentDto { * - on view: UUID="5" PROJECT_UUID="5" * - on sub-view: UUID="6" PROJECT_UUID="5" */ - private String projectUuid; + private String branchUuid; /** * Badly named, it is not the root ! @@ -177,24 +175,16 @@ public class ComponentDto { return UUID_PATH_SPLITTER.splitToList(uuidPath); } - public String getDbKey() { + public String getKey() { return kee; } - public ComponentDto setDbKey(String key) { + public ComponentDto setKey(String key) { this.kee = checkComponentKey(key); return this; } /** - * The key to be displayed to user, doesn't contain information on branches - */ - public String getKey() { - List<String> split = BRANCH_OR_PULL_REQUEST_SPLITTER.splitToList(kee); - return split.size() == 2 ? split.get(0) : kee; - } - - /** * @return the key of the branch. It will be null on the main branch and when the component is not on a branch */ @CheckForNull @@ -233,12 +223,12 @@ public class ComponentDto { /** * Return the root project uuid. On a root project, return itself */ - public String projectUuid() { - return projectUuid; + public String branchUuid() { + return branchUuid; } - public ComponentDto setProjectUuid(String projectUuid) { - this.projectUuid = projectUuid; + public ComponentDto setBranchUuid(String branchUuid) { + this.branchUuid = branchUuid; return this; } @@ -320,7 +310,7 @@ public class ComponentDto { } /** - * Use {@link #projectUuid()}, {@link #moduleUuid()} or {@link #moduleUuidPath()} + * Use {@link #branchUuid()}, {@link #moduleUuid()} or {@link #moduleUuidPath()} */ @Deprecated public String getRootUuid() { @@ -409,7 +399,7 @@ public class ComponentDto { .append("kee", kee) .append("scope", scope) .append("qualifier", qualifier) - .append("projectUuid", projectUuid) + .append("branchUuid", branchUuid) .append("moduleUuid", moduleUuid) .append("moduleUuidPath", moduleUuidPath) .append("rootUuid", rootUuid) @@ -426,11 +416,10 @@ public class ComponentDto { public ComponentDto copy() { ComponentDto copy = new ComponentDto(); - copy.projectUuid = projectUuid; copy.kee = kee; copy.uuid = uuid; copy.uuidPath = uuidPath; - copy.projectUuid = projectUuid; + copy.branchUuid = branchUuid; copy.rootUuid = rootUuid; copy.mainBranchProjectUuid = mainBranchProjectUuid; copy.moduleUuid = moduleUuid; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java index e62a69a23b7..98297278093 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java @@ -37,10 +37,10 @@ public interface ComponentMapper { ComponentDto selectByKeyCaseInsensitive(@Param("key") String key); @CheckForNull - ComponentDto selectBranchByKeyAndBranchKey(@Param("key") String key, @Param("dbKey") String dbKey, @Param("branch") String branch); + ComponentDto selectByKeyAndBranchKey(@Param("key") String key, @Param("branch") String branch); @CheckForNull - ComponentDto selectPrByKeyAndBranchKey(@Param("key") String key, @Param("dbKey") String dbKey, @Param("branch") String branch); + ComponentDto selectByKeyAndPrKey(@Param("key") String key, @Param("pr") String pr); @CheckForNull ComponentDto selectByUuid(@Param("uuid") String uuid); @@ -52,19 +52,17 @@ public interface ComponentMapper { List<ComponentDto> selectByKeys(@Param("keys") Collection<String> keys); - List<ComponentDto> selectByDbKeys(@Param("dbKeys") Collection<String> dbKeys); - List<ComponentDto> selectByKeysAndBranch(@Param("keys") Collection<String> keys, @Param("branch") String branch); List<ComponentDto> selectByUuids(@Param("uuids") Collection<String> uuids); - List<ComponentDto> selectByProjectUuid(@Param("projectUuid") String projectUuid); + List<ComponentDto> selectByBranchUuid(@Param("branchUuid") String branchUuid); List<String> selectExistingUuids(@Param("uuids") Collection<String> uuids); List<ComponentDto> selectComponentsByQualifiers(@Param("qualifiers") Collection<String> qualifiers); - int countEnabledModulesByProjectUuid(@Param("projectUuid") String projectUuid); + int countEnabledModulesByBranchUuid(@Param("branchUuid") String branchUuid); List<ComponentDto> selectByQuery(@Param("query") ComponentQuery query, RowBounds rowBounds); @@ -103,7 +101,7 @@ public interface ComponentMapper { * <p/> * It's using a join on snapshots in order to use he indexed columns snapshots.qualifier */ - List<UuidWithProjectUuidDto> selectUuidsForQualifiers(@Param("qualifiers") String... qualifiers); + List<UuidWithBranchUuidDto> selectUuidsForQualifiers(@Param("qualifiers") String... qualifiers); /** * Return components of a given scope of a project @@ -127,7 +125,7 @@ public interface ComponentMapper { void scrollForIndexing(@Param("projectUuid") @Nullable String projectUuid, ResultHandler<ComponentDto> handler); - void scrollAllFilesForFileMove(@Param("projectUuid") String projectUuid, ResultHandler<FileMoveRowDto> handler); + void scrollAllFilesForFileMove(@Param("branchUuid") String branchUuid, ResultHandler<FileMoveRowDto> handler); void insert(ComponentDto componentDto); @@ -135,11 +133,11 @@ public interface ComponentMapper { void updateBEnabledToFalse(@Param("uuids") List<String> uuids); - void applyBChangesForRootComponentUuid(@Param("projectUuid") String projectUuid); + void applyBChangesForRootComponentUuid(@Param("branchUuid") String branchUuid); - void resetBChangedForRootComponentUuid(@Param("projectUuid") String projectUuid); + void resetBChangedForRootComponentUuid(@Param("branchUuid") String branchUuid); - void setPrivateForRootComponentUuid(@Param("projectUuid") String projectUuid, @Param("isPrivate") boolean isPrivate); + void setPrivateForRootComponentUuid(@Param("branchUuid") String branchUuid, @Param("isPrivate") boolean isPrivate); void delete(String componentUuid); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentUpdateDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentUpdateDto.java index 90569194c85..7268d4b8aad 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentUpdateDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentUpdateDto.java @@ -188,7 +188,7 @@ public class ComponentUpdateDto { return new ComponentUpdateDto() .setUuid(from.uuid()) .setBChanged(false) - .setBKey(from.getDbKey()) + .setBKey(from.getKey()) .setBCopyComponentUuid(from.getCopyComponentUuid()) .setBDescription(from.description()) .setBEnabled(from.isEnabled()) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/UuidWithProjectUuidDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/UuidWithBranchUuidDto.java index 96c5c1913c7..0794cfc99b4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/UuidWithProjectUuidDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/UuidWithBranchUuidDto.java @@ -19,17 +19,17 @@ */ package org.sonar.db.component; -public class UuidWithProjectUuidDto { +public class UuidWithBranchUuidDto { private String uuid; - private String projectUuid; + private String branchUuid; - public String getProjectUuid() { - return projectUuid; + public String getBranchUuid() { + return branchUuid; } - public UuidWithProjectUuidDto setProjectUuid(String projectUuid) { - this.projectUuid = projectUuid; + public UuidWithBranchUuidDto setBranchUuid(String branchUuid) { + this.branchUuid = branchUuid; return this; } @@ -37,7 +37,7 @@ public class UuidWithProjectUuidDto { return uuid; } - public UuidWithProjectUuidDto setUuid(String uuid) { + public UuidWithBranchUuidDto setUuid(String uuid) { this.uuid = uuid; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java index 00a47fe64ee..80ccda2b0d7 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java @@ -101,7 +101,7 @@ public class IssueDao implements Dao { public List<IssueDto> selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(DbSession dbSession, ComponentDto module) { String likeModuleUuidPath = buildLikeValue(module.moduleUuidPath(), WildcardPosition.AFTER); - return mapper(dbSession).selectNonClosedByModuleOrProject(module.projectUuid(), likeModuleUuidPath); + return mapper(dbSession).selectNonClosedByModuleOrProject(module.branchUuid(), likeModuleUuidPath); } public List<PrIssueDto> selectOpenByComponentUuids(DbSession dbSession, Collection<String> componentUuids) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java index 7611cff2f3c..2e9fa59db67 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java @@ -206,7 +206,7 @@ public final class IssueDto implements Serializable { } public IssueDto setComponent(ComponentDto component) { - this.componentKey = component.getDbKey(); + this.componentKey = component.getKey(); this.componentUuid = component.uuid(); this.moduleUuidPath = component.moduleUuidPath(); this.filePath = component.path(); @@ -214,7 +214,7 @@ public final class IssueDto implements Serializable { } public IssueDto setProject(ComponentDto project) { - this.projectKey = project.getDbKey(); + this.projectKey = project.getKey(); this.projectUuid = project.uuid(); return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java index 056a1651b2d..6addf4b8359 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java @@ -47,7 +47,7 @@ public class IssueTesting { public static IssueDto newIssue(RuleDto rule, ComponentDto project, ComponentDto file) { checkArgument(project.qualifier().equals(Qualifiers.PROJECT), "Second parameter should be a project"); - return newIssue(rule, project.uuid(), project.getDbKey(), file); + return newIssue(rule, project.uuid(), project.getKey(), file); } public static IssueDto newIssue(RuleDto rule, ProjectDto project, ComponentDto file) { @@ -55,7 +55,7 @@ public class IssueTesting { } public static IssueDto newIssue(RuleDto rule, String projectUuid, String projectKey, ComponentDto file) { - checkArgument(file.projectUuid().equals(projectUuid), "The file doesn't belong to the project"); + checkArgument(file.branchUuid().equals(projectUuid), "The file doesn't belong to the project"); return new IssueDto() .setKee("uuid_" + randomAlphabetic(5)) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java index cd3f294fcc6..1e8687178d4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -34,11 +34,11 @@ public interface PurgeMapper { */ List<String> selectRootAndModulesOrSubviewsByProjectUuid(@Param("rootUuid") String rootUuid); - Set<String> selectDisabledComponentsWithFileSource(@Param("projectUuid") String projectUuid); + Set<String> selectDisabledComponentsWithFileSource(@Param("branchUuid") String branchUuid); - Set<String> selectDisabledComponentsWithUnresolvedIssues(@Param("projectUuid") String projectUuid); + Set<String> selectDisabledComponentsWithUnresolvedIssues(@Param("branchUuid") String branchUuid); - Set<String> selectDisabledComponentsWithLiveMeasures(@Param("projectUuid") String projectUuid); + Set<String> selectDisabledComponentsWithLiveMeasures(@Param("branchUuid") String branchUuid); void deleteAnalyses(@Param("analysisUuids") List<String> analysisUuids); @@ -97,7 +97,7 @@ public interface PurgeMapper { @CheckForNull String selectSpecificAnalysisNewCodePeriod(@Param("projectUuid") String projectUuid); - List<String> selectDisabledComponentsWithoutIssues(@Param("projectUuid") String projectUuid); + List<String> selectDisabledComponentsWithoutIssues(@Param("branchUuid") String branchUuid); void deleteIssuesFromKeys(@Param("keys") List<String> keys); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml index 0cdef645451..246dc8bbf43 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml @@ -225,8 +225,7 @@ select case when exists ( - select pb.project_uuid, pb.need_issue_sync from project_branches pb join components c on pb.project_uuid = - c.project_uuid + select pb.project_uuid, pb.need_issue_sync from project_branches pb join components c on pb.project_uuid = c.branch_uuid where c.kee in <foreach collection="componentKeys" open="(" close=")" item="componentKey" separator=","> #{componentKey,jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index aed19c345e9..c25cc05c20b 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -5,7 +5,7 @@ <sql id="componentColumns"> p.uuid as uuid, p.uuid_path as uuidPath, - p.project_uuid as projectUuid, + p.branch_uuid as branchUuid, p.module_uuid as moduleUuid, p.module_uuid_path as moduleUuidPath, p.main_branch_project_uuid as mainBranchProjectUuid, @@ -30,6 +30,7 @@ FROM components p where p.kee=#{key,jdbcType=VARCHAR} + and p.main_branch_project_uuid is null </select> <select id="selectByKeyCaseInsensitive" parameterType="String" resultType="Component"> @@ -40,25 +41,25 @@ lower(p.kee)=lower(#{key,jdbcType=VARCHAR}) </select> - <select id="selectBranchByKeyAndBranchKey" parameterType="String" resultType="Component"> + <select id="selectByKeyAndBranchKey" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from components p - inner join project_branches pb on pb.uuid = p.project_uuid + inner join project_branches pb on pb.uuid = p.branch_uuid where - (p.kee=#{dbKey,jdbcType=VARCHAR} OR p.kee=#{key,jdbcType=VARCHAR}) + p.kee=#{key,jdbcType=VARCHAR} and pb.kee=#{branch,jdbcType=VARCHAR} - and (pb.branch_type='BRANCH') + and pb.branch_type='BRANCH' </select> - <select id="selectPrByKeyAndBranchKey" parameterType="String" resultType="Component"> + <select id="selectByKeyAndPrKey" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from components p - inner join project_branches pb on pb.uuid = p.project_uuid + inner join project_branches pb on pb.uuid = p.branch_uuid where - (p.kee=#{dbKey,jdbcType=VARCHAR} OR p.kee=#{key,jdbcType=VARCHAR}) - and pb.kee=#{branch,jdbcType=VARCHAR} + p.kee=#{key,jdbcType=VARCHAR} + and pb.kee=#{pr,jdbcType=VARCHAR} and pb.branch_type='PULL_REQUEST' </select> @@ -70,13 +71,13 @@ p.uuid=#{uuid,jdbcType=VARCHAR} </select> - <select id="selectByProjectUuid" parameterType="string" resultType="Component"> + <select id="selectByBranchUuid" parameterType="string" resultType="Component"> select <include refid="componentColumns"/> from components root - inner join components p on p.project_uuid=root.uuid + inner join components p on p.branch_uuid=root.uuid where - root.uuid=#{projectUuid,jdbcType=VARCHAR} + root.uuid=#{branchUuid,jdbcType=VARCHAR} </select> <select id="selectByKeys" parameterType="String" resultType="Component"> @@ -92,23 +93,11 @@ </foreach> </select> - <select id="selectByDbKeys" parameterType="String" resultType="Component"> - select - <include refid="componentColumns"/> - from components p - where - p.enabled=${_true} - and p.kee in - <foreach collection="dbKeys" open="(" close=")" item="key" separator=","> - #{key,jdbcType=VARCHAR} - </foreach> - </select> - <select id="selectByKeysAndBranch" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM components p - INNER JOIN project_branches pb on pb.uuid = p.project_uuid + INNER JOIN project_branches pb on pb.uuid = p.branch_uuid <where> p.enabled=${_true} AND p.kee IN @@ -165,7 +154,7 @@ <sql id="modulesTreeQuery"> INNER JOIN components module ON - module.project_uuid = p.project_uuid + module.branch_uuid = p.branch_uuid and module.uuid = #{moduleUuid} and module.scope='PRJ' AND module.enabled = ${_true} where @@ -193,7 +182,7 @@ fs.revision FROM components root INNER JOIN components p on - p.project_uuid=root.uuid + p.branch_uuid=root.uuid and p.enabled=${_true} and p.scope='FIL' INNER JOIN file_sources fs ON @@ -236,13 +225,13 @@ </foreach> </select> - <select id="countEnabledModulesByProjectUuid" resultType="int"> + <select id="countEnabledModulesByBranchUuid" resultType="int"> select count(1) from components p where p.enabled=${_true} - and p.project_uuid = #{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid = #{branchUuid,jdbcType=VARCHAR} and p.qualifier = 'BRC' </select> @@ -388,7 +377,7 @@ <include refid="componentColumns"/> from components p where - p.project_uuid = #{branchUuid,jdbcType=VARCHAR} + p.branch_uuid = #{branchUuid,jdbcType=VARCHAR} and p.uuid_path in <foreach collection="uuidPaths" item="uuidPath" open="(" close=")" separator=","> #{uuidPath,jdbcType=VARCHAR} @@ -407,7 +396,7 @@ </select> <sql id="selectDescendantsJoins"> - inner join components base on base.project_uuid = p.project_uuid and base.uuid = #{baseUuid} + inner join components base on base.branch_uuid = p.branch_uuid and base.uuid = #{baseUuid} <choose> <when test="query.getStrategy().name() == 'CHILDREN'"> and p.uuid_path = #{baseUuidPath,jdbcType=VARCHAR} @@ -441,8 +430,8 @@ </if> </sql> - <select id="selectUuidsForQualifiers" resultType="UuidWithProjectUuid"> - SELECT p.uuid as "uuid", p.project_uuid as "projectUuid" FROM components p + <select id="selectUuidsForQualifiers" resultType="UuidWithBranchUuid"> + SELECT p.uuid as "uuid", p.branch_uuid as "branchUuid" FROM components p where <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator="OR "> p.qualifier=#{qualifier,jdbcType=VARCHAR} @@ -461,7 +450,7 @@ <foreach collection="projectUuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach> where p.enabled = ${_true} - and p.uuid = leaf.project_uuid + and p.uuid = leaf.branch_uuid and p.scope = 'PRJ' and p.qualifier in ('VW', 'APP') </select> @@ -470,7 +459,7 @@ from components p where p.enabled = ${_true} - and p.project_uuid = #{projectViewUuid,jdbcType=VARCHAR} + and p.branch_uuid = #{projectViewUuid,jdbcType=VARCHAR} <choose> <when test="_databaseId == 'mssql'"> and p.module_uuid_path like #{viewUuidLikeQuery,jdbcType=VARCHAR} {escape '\'} @@ -487,7 +476,7 @@ SELECT <include refid="componentColumns"/> FROM components p - INNER JOIN components root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} + INNER JOIN components root ON root.uuid=p.branch_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} <where> <if test="excludeDisabled"> p.enabled = ${_true} @@ -504,7 +493,7 @@ FROM components p INNER JOIN - components root ON root.uuid=p.project_uuid AND p.enabled = ${_true} AND root.kee=#{projectKey,jdbcType=VARCHAR} + components root ON root.uuid=p.branch_uuid AND p.enabled = ${_true} AND root.kee=#{projectKey,jdbcType=VARCHAR} </select> <select id="selectUuidsByKeyFromProjectKey" parameterType="string" resultType="KeyWithUuid"> @@ -513,7 +502,7 @@ FROM components p INNER JOIN - components root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} + components root ON root.uuid=p.branch_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} </select> <select id="scrollForIndexing" parameterType="map" resultType="Component" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY"> @@ -527,7 +516,7 @@ and p.scope = 'PRJ' and p.qualifier in ('TRK','VW','SVW','APP') <if test="projectUuid != null"> - and p.project_uuid = #{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid = #{projectUuid,jdbcType=VARCHAR} </if> </select> @@ -541,7 +530,7 @@ inner join file_sources fs on fs.file_uuid = p.uuid where - p.project_uuid = #{projectUuid,jdbcType=VARCHAR} + p.branch_uuid = #{branchUuid,jdbcType=VARCHAR} and p.enabled = ${_true} and p.scope = 'FIL' and p.qualifier in ('FIL', 'UTS') @@ -553,7 +542,7 @@ kee, uuid, uuid_path, - project_uuid, + branch_uuid, module_uuid, module_uuid_path, main_branch_project_uuid, @@ -586,7 +575,7 @@ #{kee,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}, #{uuidPath,jdbcType=VARCHAR}, - #{projectUuid,jdbcType=VARCHAR}, + #{branchUuid,jdbcType=VARCHAR}, #{moduleUuid,jdbcType=VARCHAR}, #{moduleUuidPath,jdbcType=VARCHAR}, #{mainBranchProjectUuid, jdbcType=VARCHAR}, @@ -699,7 +688,7 @@ b_path = null, b_qualifier = null where - project_uuid = #{projectUuid,jdbcType=VARCHAR} and + branch_uuid = #{branchUuid,jdbcType=VARCHAR} and b_changed = ${_true} </update> @@ -709,7 +698,7 @@ <!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules --> deprecated_kee = kee where - project_uuid = #{projectUuid,jdbcType=VARCHAR} and + branch_uuid = #{branchUuid,jdbcType=VARCHAR} and b_changed = ${_true} </update> @@ -717,7 +706,7 @@ update components set private = #{isPrivate,jdbcType=BOOLEAN} where - project_uuid = #{projectUuid,jdbcType=VARCHAR} + branch_uuid = #{branchUuid,jdbcType=VARCHAR} and private <> #{isPrivate,jdbcType=BOOLEAN} </update> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml index 513386f1322..575645a72c6 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml @@ -38,7 +38,7 @@ <select id="selectLastSnapshotByComponentUuid" resultType="Snapshot"> select <include refid="snapshotColumns" /> from snapshots s - inner join components p on s.component_uuid = p.project_uuid + inner join components p on s.component_uuid = p.branch_uuid where s.islast=${_true} and p.uuid = #{componentUuid,jdbcType=VARCHAR} @@ -47,10 +47,10 @@ <select id="selectLastAnalysisDateByProject" resultType="long"> select max(s.created_at) from snapshots s - inner join components p on s.component_uuid = p.project_uuid + inner join components p on s.component_uuid = p.branch_uuid where s.islast=${_true} - and coalesce(p.main_branch_project_uuid, p.project_uuid) = #{projectUuid,jdbcType=VARCHAR} + and coalesce(p.main_branch_project_uuid, p.branch_uuid) = #{projectUuid,jdbcType=VARCHAR} </select> <select id="selectLastAnalysisDateByProjects" resultType="org.sonar.db.component.ProjectLastAnalysisDateDto"> @@ -65,7 +65,7 @@ from snapshots s inner join components c on - s.component_uuid = c.project_uuid + s.component_uuid = c.branch_uuid where s.islast = ${_true} and c.main_branch_project_uuid in @@ -76,21 +76,21 @@ c.main_branch_project_uuid union select - c.project_uuid as project_uuid, + c.branch_uuid as project_uuid, max(s.created_at) as last_analysis_date from snapshots s inner join components c on - s.component_uuid = c.project_uuid + s.component_uuid = c.branch_uuid where s.islast = ${_true} and c.main_branch_project_uuid is null - and c.project_uuid in + and c.branch_uuid in <foreach collection="projectUuids" item="projectUuid" separator="," open="(" close=")"> #{projectUuid,jdbcType=VARCHAR} </foreach> group by - c.project_uuid + c.branch_uuid ) result_with_duplicates group by result_with_duplicates.project_uuid diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index 20df7611c2b..db14d3c6646 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -69,7 +69,7 @@ components p where ( - p.project_uuid=#{rootUuid,jdbcType=VARCHAR} + p.branch_uuid=#{rootUuid,jdbcType=VARCHAR} and p.scope = 'PRJ' and p.qualifier in ('SVW','BRC') ) or ( @@ -85,7 +85,7 @@ inner join components p on p.uuid = fs.file_uuid and p.enabled = ${_false} - and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR} </select> <select id="selectDisabledComponentsWithUnresolvedIssues" parameterType="map" resultType="String"> @@ -95,7 +95,7 @@ inner join components p on p.uuid = i.component_uuid and p.enabled = ${_false} - and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR} where resolution is null </select> @@ -107,7 +107,7 @@ inner join components p on p.uuid = lm.component_uuid and p.enabled = ${_false} - and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR} </select> <delete id="deleteAnalysisMeasures" parameterType="map"> @@ -220,7 +220,7 @@ <delete id="deleteComponentsByProjectUuid" parameterType="map"> delete from components where - project_uuid = #{rootUuid,jdbcType=VARCHAR} + branch_uuid = #{rootUuid,jdbcType=VARCHAR} </delete> <delete id="deleteComponentsByMainBranchProjectUuid" parameterType="map"> @@ -322,7 +322,7 @@ components p WHERE p.enabled = ${_false} - AND p.project_uuid=#{projectUuid,jdbcType=VARCHAR} + AND p.branch_uuid=#{branchUuid,jdbcType=VARCHAR} AND NOT EXISTS (SELECT 1 FROM issues i WHERE i.component_uuid = p.uuid) </select> diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index f161a202ff6..fae462a9976 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -215,7 +215,7 @@ CREATE TABLE "COMPONENTS"( "COPY_COMPONENT_UUID" CHARACTER VARYING(50), "PATH" CHARACTER VARYING(2000), "UUID_PATH" CHARACTER VARYING(1500) NOT NULL, - "PROJECT_UUID" CHARACTER VARYING(50) NOT NULL, + "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL, "MODULE_UUID" CHARACTER VARYING(50), "MODULE_UUID_PATH" CHARACTER VARYING(1500), "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50), @@ -233,13 +233,12 @@ CREATE TABLE "COMPONENTS"( "B_MODULE_UUID_PATH" CHARACTER VARYING(1500), "CREATED_AT" TIMESTAMP ); -CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE" NULLS FIRST); CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID" NULLS FIRST); -CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID" NULLS FIRST); CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST); CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST); CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST); CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST); +CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST); CREATE TABLE "DEFAULT_QPROFILES"( "LANGUAGE" CHARACTER VARYING(20) NOT NULL, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java index d760751fac2..2eb980d3913 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java @@ -702,12 +702,12 @@ public class CeQueueDaoTest { private void insertView(String view_uuid) { ComponentDto view = new ComponentDto(); view.setQualifier("VW"); - view.setDbKey(view_uuid + "_key"); + view.setKey(view_uuid + "_key"); view.setUuid(view_uuid); view.setPrivate(false); view.setRootUuid(view_uuid); view.setUuidPath("uuid_path"); - view.setProjectUuid(view_uuid); + view.setBranchUuid(view_uuid); db.components().insertPortfolioAndSnapshot(view); db.commit(); } @@ -715,12 +715,12 @@ public class CeQueueDaoTest { private void insertBranch(String uuid) { ComponentDto branch = new ComponentDto(); branch.setQualifier("TRK"); - branch.setDbKey(uuid + "_key"); + branch.setKey(uuid + "_key"); branch.setUuid(uuid); branch.setPrivate(false); branch.setRootUuid(uuid); branch.setUuidPath("uuid_path"); - branch.setProjectUuid(uuid); + branch.setBranchUuid(uuid); db.components().insertComponent(branch); db.commit(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ApplicationProjectsDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ApplicationProjectsDaoTest.java index 7e016ddfe3a..7c8d24a49cc 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ApplicationProjectsDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ApplicationProjectsDaoTest.java @@ -79,9 +79,9 @@ public class ApplicationProjectsDaoTest { @Test public void select_project_branches_from_application_branch() { - var project = db.components().insertPublicProjectDto(p -> p.setDbKey("project")); + var project = db.components().insertPublicProjectDto(p -> p.setKey("project")); var projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch")); - var app = db.components().insertPrivateApplicationDto(a -> a.setDbKey("app1")); + var app = db.components().insertPrivateApplicationDto(a -> a.setKey("app1")); var appBranch = db.components().insertProjectBranch(app, b -> b.setKey("app-branch")); db.components().addApplicationProject(app, project); underTest.addProjectBranchToAppBranch(dbSession, app.getUuid(), appBranch.getUuid(), project.getUuid(), projectBranch.getUuid()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java index e58113a3212..5de47d10d24 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java @@ -425,7 +425,7 @@ public class BranchDaoTest { featureBranch.setMergeBranchUuid("U3"); underTest.insert(dbSession, featureBranch); - ComponentDto component = new ComponentDto().setProjectUuid(mainBranch.getUuid()); + ComponentDto component = new ComponentDto().setBranchUuid(mainBranch.getUuid()); // select the component Collection<BranchDto> branches = underTest.selectByComponent(dbSession, component); @@ -736,7 +736,7 @@ public class BranchDaoTest { @Test public void doAnyOfComponentsNeedIssueSync_test_more_than_1000() { List<String> componentKeys = IntStream.range(0, 1100).mapToObj(value -> db.components().insertPrivateProject()) - .map(ComponentDto::getDbKey) + .map(ComponentDto::getKey) .collect(Collectors.toList()); assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, componentKeys)).isFalse(); @@ -745,7 +745,7 @@ public class BranchDaoTest { ProjectDto projectDto = db.components().getProjectDto(project); db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true)); - componentKeys.add(project.getDbKey()); + componentKeys.add(project.getKey()); assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, componentKeys)).isTrue(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 0996f6a56ff..8104002008b 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -19,7 +19,6 @@ */ package org.sonar.db.component; -import com.google.common.collect.ImmutableMap; import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; @@ -130,7 +129,7 @@ public class ComponentDaoTest { @Test public void get_by_uuid() { ComponentDto project = db.components().insertPrivateProject(p -> p - .setDbKey("org.struts:struts") + .setKey("org.struts:struts") .setName("Struts") .setLongName("Apache Struts")); ComponentDto anotherProject = db.components().insertPrivateProject(); @@ -141,8 +140,8 @@ public class ComponentDaoTest { assertThat(result.getUuidPath()).isEqualTo("."); assertThat(result.moduleUuid()).isNull(); assertThat(result.moduleUuidPath()).isEqualTo("." + project.uuid() + "."); - assertThat(result.projectUuid()).isEqualTo(project.uuid()); - assertThat(result.getDbKey()).isEqualTo("org.struts:struts"); + assertThat(result.branchUuid()).isEqualTo(project.uuid()); + assertThat(result.getKey()).isEqualTo("org.struts:struts"); assertThat(result.path()).isNull(); assertThat(result.name()).isEqualTo("Struts"); assertThat(result.longName()).isEqualTo("Apache Struts"); @@ -159,7 +158,7 @@ public class ComponentDaoTest { public void get_by_uuid_on_technical_project_copy() { ComponentDto view = db.components().insertPublicPortfolio(); ComponentDto project = db.components().insertPublicProject(p -> p - .setDbKey("org.struts:struts") + .setKey("org.struts:struts") .setName("Struts") .setLongName("Apache Struts")); ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(project, view)); @@ -170,8 +169,8 @@ public class ComponentDaoTest { assertThat(result.uuid()).isEqualTo(projectCopy.uuid()); assertThat(result.moduleUuid()).isEqualTo(view.uuid()); assertThat(result.moduleUuidPath()).isEqualTo("." + view.uuid() + "."); - assertThat(result.projectUuid()).isEqualTo(view.uuid()); - assertThat(result.getDbKey()).isEqualTo(view.getDbKey() + project.getDbKey()); + assertThat(result.branchUuid()).isEqualTo(view.uuid()); + assertThat(result.getKey()).isEqualTo(view.getKey() + project.getKey()); assertThat(result.path()).isNull(); assertThat(result.name()).isEqualTo("Struts"); assertThat(result.longName()).isEqualTo("Apache Struts"); @@ -205,24 +204,24 @@ public class ComponentDaoTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto directory = db.components().insertComponent(newDirectory(project, "src")); ComponentDto file = db.components().insertComponent(newFileDto(project, directory) - .setDbKey("org.struts:struts-core:src/org/struts/RequestContext.java") + .setKey("org.struts:struts-core:src/org/struts/RequestContext.java") .setName("RequestContext.java") .setLongName("org.struts.RequestContext") .setLanguage("java") .setPath("src/RequestContext.java")); - Optional<ComponentDto> optional = underTest.selectByKey(dbSession, file.getDbKey()); + Optional<ComponentDto> optional = underTest.selectByKey(dbSession, file.getKey()); ComponentDto result = optional.get(); assertThat(result.uuid()).isEqualTo(file.uuid()); - assertThat(result.getDbKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); + assertThat(result.getKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); assertThat(result.path()).isEqualTo("src/RequestContext.java"); assertThat(result.name()).isEqualTo("RequestContext.java"); assertThat(result.longName()).isEqualTo("org.struts.RequestContext"); assertThat(result.qualifier()).isEqualTo("FIL"); assertThat(result.scope()).isEqualTo("FIL"); assertThat(result.language()).isEqualTo("java"); - assertThat(result.projectUuid()).isEqualTo(project.uuid()); + assertThat(result.branchUuid()).isEqualTo(project.uuid()); assertThat(underTest.selectByKey(dbSession, "unknown")).isEmpty(); } @@ -250,9 +249,7 @@ public class ComponentDaoTest { ComponentDto file = db.components().insertComponent(newFileDto(pullRequest)); assertThat(underTest.selectByKeyAndPullRequest(dbSession, project.getKey(), "my_PR").get().uuid()).isEqualTo(pullRequest.uuid()); - assertThat(underTest.selectByKeyAndBranch(dbSession, project.getKey(), "master").get().uuid()).isEqualTo(project.uuid()); assertThat(underTest.selectByKeyAndPullRequest(dbSession, project.getKey(), "master").get().uuid()).isEqualTo(pullRequestNamedAsMainBranch.uuid()); - assertThat(underTest.selectByKeyAndBranch(dbSession, branch.getKey(), "my_branch").get().uuid()).isEqualTo(branch.uuid()); assertThat(underTest.selectByKeyAndPullRequest(dbSession, branch.getKey(), "my_branch").get().uuid()).isEqualTo(pullRequestNamedAsBranch.uuid()); assertThat(underTest.selectByKeyAndPullRequest(dbSession, file.getKey(), "my_PR").get().uuid()).isEqualTo(file.uuid()); assertThat(underTest.selectByKeyAndPullRequest(dbSession, "unknown", "my_branch")).isNotPresent(); @@ -271,7 +268,7 @@ public class ComponentDaoTest { public void get_by_key_on_disabled_component() { ComponentDto project = db.components().insertPrivateProject(p -> p.setEnabled(false)); - ComponentDto result = underTest.selectOrFailByKey(dbSession, project.getDbKey()); + ComponentDto result = underTest.selectOrFailByKey(dbSession, project.getKey()); assertThat(result.isEnabled()).isFalse(); } @@ -280,13 +277,13 @@ public class ComponentDaoTest { public void get_by_key_on_a_root_project() { ComponentDto project = db.components().insertPrivateProject(); - ComponentDto result = underTest.selectOrFailByKey(dbSession, project.getDbKey()); + ComponentDto result = underTest.selectOrFailByKey(dbSession, project.getKey()); - assertThat(result.getDbKey()).isEqualTo(project.getDbKey()); + assertThat(result.getKey()).isEqualTo(project.getKey()); assertThat(result.uuid()).isEqualTo(project.uuid()); assertThat(result.getUuidPath()).isEqualTo(project.getUuidPath()); assertThat(result.getRootUuid()).isEqualTo(project.uuid()); - assertThat(result.projectUuid()).isEqualTo(project.uuid()); + assertThat(result.branchUuid()).isEqualTo(project.uuid()); } @Test @@ -294,13 +291,13 @@ public class ComponentDaoTest { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); - List<ComponentDto> results = underTest.selectByKeys(dbSession, asList(project1.getDbKey(), project2.getDbKey())); + List<ComponentDto> results = underTest.selectByKeys(dbSession, asList(project1.getKey(), project2.getKey())); assertThat(results) - .extracting(ComponentDto::uuid, ComponentDto::getDbKey) + .extracting(ComponentDto::uuid, ComponentDto::getKey) .containsExactlyInAnyOrder( - tuple(project1.uuid(), project1.getDbKey()), - tuple(project2.uuid(), project2.getDbKey())); + tuple(project1.uuid(), project1.getKey()), + tuple(project2.uuid(), project2.getKey())); assertThat(underTest.selectByKeys(dbSession, singletonList("unknown"))).isEmpty(); } @@ -321,29 +318,7 @@ public class ComponentDaoTest { assertThat(underTest.selectByKeysAndBranch(dbSession, singletonList(fileOnAnotherBranch.getKey()), "my_branch")).isEmpty(); assertThat(underTest.selectByKeysAndBranch(dbSession, singletonList(file1.getKey()), "unknown")).isEmpty(); assertThat(underTest.selectByKeysAndBranch(dbSession, singletonList("unknown"), "my_branch")).isEmpty(); - assertThat(underTest.selectByKeysAndBranch(dbSession, singletonList(branch.getKey()), "master")).extracting(ComponentDto::uuid).containsExactlyInAnyOrder(project.uuid()); - } - - @Test - public void select_by_keys_and_branches() { - ComponentDto project = db.components().insertPublicProject(); - ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); - ComponentDto application = db.components().insertPublicProject(a -> a.setQualifier(APP)); - ComponentDto applicationBranch = db.components().insertProjectBranch(application, b -> b.setKey("my_branch")); - - assertThat(underTest.selectByKeysAndBranches(db.getSession(), ImmutableMap.of( - projectBranch.getKey(), projectBranch.getBranch(), - applicationBranch.getKey(), applicationBranch.getBranch()))) - .extracting(ComponentDto::getKey, ComponentDto::getBranch) - .containsExactlyInAnyOrder( - tuple(projectBranch.getKey(), "my_branch"), - tuple(applicationBranch.getKey(), "my_branch")); - assertThat(underTest.selectByKeysAndBranches(db.getSession(), ImmutableMap.of( - projectBranch.getKey(), "unknown", - "unknown", projectBranch.getBranch()))) - .extracting(ComponentDto::getDbKey) - .isEmpty(); - assertThat(underTest.selectByKeysAndBranches(db.getSession(), Collections.emptyMap())).isEmpty(); + assertThat(underTest.selectByKeysAndBranch(dbSession, singletonList(branch.getKey()), "my_branch")).extracting(ComponentDto::uuid).containsExactlyInAnyOrder(branch.uuid()); } @Test @@ -354,10 +329,10 @@ public class ComponentDaoTest { List<ComponentDto> results = underTest.selectByUuids(dbSession, asList(project1.uuid(), project2.uuid())); assertThat(results) - .extracting(ComponentDto::uuid, ComponentDto::getDbKey) + .extracting(ComponentDto::uuid, ComponentDto::getKey) .containsExactlyInAnyOrder( - tuple(project1.uuid(), project1.getDbKey()), - tuple(project2.uuid(), project2.getDbKey())); + tuple(project1.uuid(), project1.getKey()), + tuple(project2.uuid(), project2.getKey())); assertThat(underTest.selectByUuids(dbSession, singletonList("unknown"))).isEmpty(); } @@ -370,10 +345,10 @@ public class ComponentDaoTest { List<ComponentDto> results = underTest.selectByUuids(dbSession, asList(project1.uuid(), project2.uuid())); assertThat(results) - .extracting(ComponentDto::getDbKey, ComponentDto::isEnabled) + .extracting(ComponentDto::getKey, ComponentDto::isEnabled) .containsExactlyInAnyOrder( - tuple(project1.getDbKey(), true), - tuple(project2.getDbKey(), false)); + tuple(project1.getKey(), true), + tuple(project2.getKey(), false)); } @Test @@ -393,10 +368,10 @@ public class ComponentDaoTest { ComponentDto directory = db.components().insertComponent(newDirectory(module, "src")); ComponentDto file = db.components().insertComponent(newFileDto(directory)); - assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("TRK"))).extracting(ComponentDto::getDbKey).containsExactlyInAnyOrder(project.getDbKey()); - assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("BRC"))).extracting(ComponentDto::getDbKey).containsExactlyInAnyOrder(module.getDbKey()); - assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("DIR"))).extracting(ComponentDto::getDbKey).containsExactlyInAnyOrder(directory.getDbKey()); - assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("FIL"))).extracting(ComponentDto::getDbKey).containsExactlyInAnyOrder(file.getDbKey()); + assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("TRK"))).extracting(ComponentDto::getKey).containsExactlyInAnyOrder(project.getKey()); + assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("BRC"))).extracting(ComponentDto::getKey).containsExactlyInAnyOrder(module.getKey()); + assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("DIR"))).extracting(ComponentDto::getKey).containsExactlyInAnyOrder(directory.getKey()); + assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("FIL"))).extracting(ComponentDto::getKey).containsExactlyInAnyOrder(file.getKey()); assertThat(underTest.selectComponentsByQualifiers(dbSession, newHashSet("unknown"))).isEmpty(); } @@ -417,7 +392,7 @@ public class ComponentDaoTest { subModule2.setEnabled(false); db.components().insertComponent(subModule2); - int result = underTest.countEnabledModulesByProjectUuid(dbSession, project.uuid()); + int result = underTest.countEnabledModulesByBranchUuid(dbSession, project.uuid()); assertThat(result).isEqualTo(2); } @@ -437,8 +412,8 @@ public class ComponentDaoTest { // Sub project of a file assertThat(underTest.selectSubProjectsByComponentUuids(dbSession, singletonList(file.uuid()))) - .extracting(ComponentDto::getDbKey) - .containsExactlyInAnyOrder(subModule.getDbKey()); + .extracting(ComponentDto::getKey) + .containsExactlyInAnyOrder(subModule.getKey()); // Sub project of a directory assertThat(underTest.selectSubProjectsByComponentUuids(dbSession, singletonList(directory.uuid()))) @@ -518,7 +493,7 @@ public class ComponentDaoTest { ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false)); // From root project - assertThat(underTest.selectEnabledComponentsWithModuleUuidFromProjectKey(dbSession, project.getDbKey())) + assertThat(underTest.selectEnabledComponentsWithModuleUuidFromProjectKey(dbSession, project.getKey())) .extracting(ComponentWithModuleUuidDto::uuid) .containsExactlyInAnyOrder( project.uuid(), @@ -636,10 +611,10 @@ public class ComponentDaoTest { ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false)); // Removed components are included - assertThat(underTest.selectAllComponentsFromProjectKey(dbSession, project.getDbKey())) - .extracting(ComponentDto::getDbKey) - .containsExactlyInAnyOrder(project.getDbKey(), module.getDbKey(), removedModule.getDbKey(), subModule.getDbKey(), removedSubModule.getDbKey(), - directory.getDbKey(), removedDirectory.getDbKey(), file.getDbKey(), removedFile.getDbKey()); + assertThat(underTest.selectAllComponentsFromProjectKey(dbSession, project.getKey())) + .extracting(ComponentDto::getKey) + .containsExactlyInAnyOrder(project.getKey(), module.getKey(), removedModule.getKey(), subModule.getKey(), removedSubModule.getKey(), + directory.getKey(), removedDirectory.getKey(), file.getKey(), removedFile.getKey()); assertThat(underTest.selectAllComponentsFromProjectKey(dbSession, "UNKNOWN")).isEmpty(); } @@ -657,19 +632,19 @@ public class ComponentDaoTest { ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory)); ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false)); - Map<String, String> uuidsByKey = underTest.selectUuidsByKeyFromProjectKey(dbSession, project.getDbKey()) + Map<String, String> uuidsByKey = underTest.selectUuidsByKeyFromProjectKey(dbSession, project.getKey()) .stream().collect(Collectors.toMap(KeyWithUuidDto::key, KeyWithUuidDto::uuid)); assertThat(uuidsByKey).containsOnly( - entry(project.getDbKey(), project.uuid()), - entry(module.getDbKey(), module.uuid()), - entry(removedModule.getDbKey(), removedModule.uuid()), - entry(subModule.getDbKey(), subModule.uuid()), - entry(removedSubModule.getDbKey(), removedSubModule.uuid()), - entry(directory.getDbKey(), directory.uuid()), - entry(removedDirectory.getDbKey(), removedDirectory.uuid()), - entry(file.getDbKey(), file.uuid()), - entry(removedFile.getDbKey(), removedFile.uuid())); + entry(project.getKey(), project.uuid()), + entry(module.getKey(), module.uuid()), + entry(removedModule.getKey(), removedModule.uuid()), + entry(subModule.getKey(), subModule.uuid()), + entry(removedSubModule.getKey(), removedSubModule.uuid()), + entry(directory.getKey(), directory.uuid()), + entry(removedDirectory.getKey(), removedDirectory.uuid()), + entry(file.getKey(), file.uuid()), + entry(removedFile.getKey(), removedFile.uuid())); } @Test @@ -686,9 +661,9 @@ public class ComponentDaoTest { ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false)); // Removed modules are not included - assertThat(underTest.selectEnabledModulesFromProjectKey(dbSession, project.getDbKey())) - .extracting(ComponentDto::getDbKey) - .containsExactlyInAnyOrder(project.getDbKey(), module.getDbKey(), subModule.getDbKey()); + assertThat(underTest.selectEnabledModulesFromProjectKey(dbSession, project.getKey())) + .extracting(ComponentDto::getKey) + .containsExactlyInAnyOrder(project.getKey(), module.getKey(), subModule.getKey()); assertThat(underTest.selectEnabledModulesFromProjectKey(dbSession, "UNKNOWN")).isEmpty(); } @@ -704,10 +679,10 @@ public class ComponentDaoTest { db.components().insertSubView(view, dto -> dto.setUuid("FGHI")); ComponentDto application = db.components().insertPublicApplication(); - assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getUuid) + assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithBranchUuidDto::getUuid) .containsExactlyInAnyOrder("ABCD", "EFGH", "FGHI", "IJKL", application.uuid()); - assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getProjectUuid) - .containsExactlyInAnyOrder("ABCD", "EFGH", "EFGH", "IJKL", application.projectUuid()); + assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithBranchUuidDto::getBranchUuid) + .containsExactlyInAnyOrder("ABCD", "EFGH", "EFGH", "IJKL", application.branchUuid()); } @Test @@ -743,7 +718,7 @@ public class ComponentDaoTest { Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project.uuid())); - assertThat(keys).containsOnly(view.getDbKey()); + assertThat(keys).containsOnly(view.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project.uuid()))) .isEqualTo(keys); @@ -762,25 +737,25 @@ public class ComponentDaoTest { insertProjectCopy(view2, project3); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project1.uuid()))) - .containsOnly(view.getDbKey()); + .containsOnly(view.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project1.uuid()))) - .containsOnly(view.getDbKey()); + .containsOnly(view.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project2.uuid()))) - .containsOnly(view.getDbKey()); + .containsOnly(view.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project2.uuid()))) - .containsOnly(view.getDbKey()); + .containsOnly(view.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project3.uuid()))) - .containsOnly(view2.getDbKey()); + .containsOnly(view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project3.uuid()))) - .containsOnly(view2.getDbKey()); + .containsOnly(view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, of(project2.uuid(), project1.uuid()))) - .containsOnly(view.getDbKey()); + .containsOnly(view.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project2.uuid(), project1.uuid()))) - .containsOnly(view.getDbKey()); + .containsOnly(view.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, of(project1.uuid(), project3.uuid()))) - .containsOnly(view.getDbKey(), view2.getDbKey()); + .containsOnly(view.getKey(), view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project1.uuid(), project3.uuid()))) - .containsOnly(view.getDbKey(), view2.getDbKey()); + .containsOnly(view.getKey(), view2.getKey()); } @Test @@ -795,7 +770,7 @@ public class ComponentDaoTest { Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project2.uuid())); - assertThat(keys).containsOnly(view2.getDbKey()); + assertThat(keys).containsOnly(view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project2.uuid()))) .isEqualTo(keys); @@ -812,7 +787,7 @@ public class ComponentDaoTest { Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project.uuid())); - assertThat(keys).containsOnly(view1.getDbKey()); + assertThat(keys).containsOnly(view1.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project.uuid()))) .isEqualTo(keys); @@ -829,7 +804,7 @@ public class ComponentDaoTest { Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project.uuid())); - assertThat(keys).containsOnly(view2.getDbKey()); + assertThat(keys).containsOnly(view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project.uuid()))) .isEqualTo(keys); @@ -845,7 +820,7 @@ public class ComponentDaoTest { Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project.uuid())); - assertThat(keys).containsOnly(view.getDbKey()); + assertThat(keys).containsOnly(view.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project.uuid()))) .isEqualTo(keys); @@ -866,25 +841,25 @@ public class ComponentDaoTest { insertProjectCopy(lowestSubview2, project3); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project1.uuid()))) - .containsOnly(view1.getDbKey()); + .containsOnly(view1.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project1.uuid()))) - .containsOnly(view1.getDbKey()); + .containsOnly(view1.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project2.uuid()))) - .containsOnly(view1.getDbKey()); + .containsOnly(view1.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project2.uuid()))) - .containsOnly(view1.getDbKey()); + .containsOnly(view1.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project3.uuid()))) - .containsOnly(view2.getDbKey()); + .containsOnly(view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project3.uuid()))) - .containsOnly(view2.getDbKey()); + .containsOnly(view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, of(project2.uuid(), project1.uuid()))) - .containsOnly(view1.getDbKey()); + .containsOnly(view1.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project2.uuid(), project1.uuid()))) - .containsOnly(view1.getDbKey()); + .containsOnly(view1.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, of(project1.uuid(), project3.uuid()))) - .containsOnly(view1.getDbKey(), view2.getDbKey()); + .containsOnly(view1.getKey(), view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project1.uuid(), project3.uuid()))) - .containsOnly(view1.getDbKey(), view2.getDbKey()); + .containsOnly(view1.getKey(), view2.getKey()); } @Test @@ -901,7 +876,7 @@ public class ComponentDaoTest { Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project2.uuid())); - assertThat(keys).containsOnly(view2.getDbKey()); + assertThat(keys).containsOnly(view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project2.uuid()))) .isEqualTo(keys); @@ -920,7 +895,7 @@ public class ComponentDaoTest { Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project.uuid())); - assertThat(keys).containsOnly(view1.getDbKey()); + assertThat(keys).containsOnly(view1.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project.uuid()))) .isEqualTo(keys); @@ -939,7 +914,7 @@ public class ComponentDaoTest { Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project.uuid())); - assertThat(keys).containsOnly(view2.getDbKey()); + assertThat(keys).containsOnly(view2.getKey()); assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, shuffleWithNonExistentUuids(project.uuid()))) .isEqualTo(keys); @@ -1050,7 +1025,7 @@ public class ComponentDaoTest { @Test public void selectByQuery_provisioned() { ComponentDto provisionedProject = db.components() - .insertPrivateProject(p -> p.setDbKey("provisioned.project").setName("Provisioned Project")); + .insertPrivateProject(p -> p.setKey("provisioned.project").setName("Provisioned Project")); ComponentDto provisionedPortfolio = db.components().insertPrivatePortfolio(); SnapshotDto analyzedProject = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); @@ -1076,7 +1051,7 @@ public class ComponentDaoTest { .containsOnly(provisionedProject.uuid(), provisionedPortfolio.uuid()); // match key - assertThat(underTest.selectByQuery(dbSession, query.get().setNameOrKeyQuery(provisionedProject.getDbKey()).build(), 0, 10)) + assertThat(underTest.selectByQuery(dbSession, query.get().setNameOrKeyQuery(provisionedProject.getKey()).build(), 0, 10)) .extracting(ComponentDto::uuid) .containsExactly(provisionedProject.uuid()); assertThat(underTest.selectByQuery(dbSession, query.get().setNameOrKeyQuery("pROvisiONed.proJEcT").setPartialMatchOnKey(true).build(), 0, 10)) @@ -1188,7 +1163,7 @@ public class ComponentDaoTest { ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory)); ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false)); - assertThat(underTest.selectByProjectUuid(project.uuid(), dbSession)) + assertThat(underTest.selectByBranchUuid(project.uuid(), dbSession)) .extracting(ComponentDto::uuid) .containsExactlyInAnyOrder(project.uuid(), module.uuid(), removedModule.uuid(), subModule.uuid(), removedSubModule.uuid(), directory.uuid(), removedDirectory.uuid(), file.uuid(), @@ -1294,7 +1269,7 @@ public class ComponentDaoTest { Map<String, Object> row1 = selectBColumnsForUuid("U1"); assertThat(row1.get("bChanged")).isIn(true, /* for Oracle */1L, 1); assertThat(row1) - .containsEntry("bKey", dto1.getDbKey()) + .containsEntry("bKey", dto1.getKey()) .containsEntry("bCopyComponentUuid", dto1.getCopyComponentUuid()) .containsEntry("bDescription", dto1.description()); assertThat(row1.get("bEnabled")).isIn(false, /* for Oracle */0L, 0); @@ -1311,7 +1286,7 @@ public class ComponentDaoTest { Map<String, Object> row2 = selectBColumnsForUuid("U2"); assertThat(row2.get("bChanged")).isIn(true, /* for Oracle */1L, 1); assertThat(row2) - .containsEntry("bKey", dto2.getDbKey()) + .containsEntry("bKey", dto2.getKey()) .containsEntry("bCopyComponentUuid", dto2.getCopyComponentUuid()) .containsEntry("bDescription", dto2.description()); assertThat(row2.get("bEnabled")).isIn(false, /* for Oracle */0L, 0); @@ -1412,19 +1387,19 @@ public class ComponentDaoTest { @Test public void selectByQuery_key_with_special_characters() { - db.components().insertProjectAndSnapshot(newPrivateProjectDto().setDbKey("project-_%-key")); - db.components().insertProjectAndSnapshot(newPrivateProjectDto().setDbKey("project-key-that-does-not-match")); + db.components().insertProjectAndSnapshot(newPrivateProjectDto().setKey("project-_%-key")); + db.components().insertProjectAndSnapshot(newPrivateProjectDto().setKey("project-key-that-does-not-match")); ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-key").setQualifiers(PROJECT).build(); List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10); assertThat(result).hasSize(1); - assertThat(result.get(0).getDbKey()).isEqualTo("project-_%-key"); + assertThat(result.get(0).getKey()).isEqualTo("project-_%-key"); } @Test public void selectByQuery_on_key_partial_match_case_insensitive() { - db.components().insertProjectAndSnapshot(newPrivateProjectDto().setDbKey("project-key")); + db.components().insertProjectAndSnapshot(newPrivateProjectDto().setKey("project-key")); ComponentQuery query = ComponentQuery.builder() .setNameOrKeyQuery("JECT-K") @@ -1433,7 +1408,7 @@ public class ComponentDaoTest { List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10); assertThat(result).hasSize(1); - assertThat(result.get(0).getDbKey()).isEqualTo("project-key"); + assertThat(result.get(0).getKey()).isEqualTo("project-key"); } @Test @@ -1579,16 +1554,16 @@ public class ComponentDaoTest { @Test public void selectByQuery_filter_on_visibility() { - db.components().insertComponent(newPrivateProjectDto().setDbKey("private-key")); - db.components().insertComponent(ComponentTesting.newPublicProjectDto().setDbKey("public-key")); + db.components().insertComponent(newPrivateProjectDto().setKey("private-key")); + db.components().insertComponent(ComponentTesting.newPublicProjectDto().setKey("public-key")); ComponentQuery privateProjectsQuery = ComponentQuery.builder().setPrivate(true).setQualifiers(PROJECT).build(); ComponentQuery publicProjectsQuery = ComponentQuery.builder().setPrivate(false).setQualifiers(PROJECT).build(); ComponentQuery allProjectsQuery = ComponentQuery.builder().setPrivate(null).setQualifiers(PROJECT).build(); - assertThat(underTest.selectByQuery(dbSession, privateProjectsQuery, 0, 10)).extracting(ComponentDto::getDbKey).containsExactly("private-key"); - assertThat(underTest.selectByQuery(dbSession, publicProjectsQuery, 0, 10)).extracting(ComponentDto::getDbKey).containsExactly("public-key"); - assertThat(underTest.selectByQuery(dbSession, allProjectsQuery, 0, 10)).extracting(ComponentDto::getDbKey).containsOnly("public-key", "private-key"); + assertThat(underTest.selectByQuery(dbSession, privateProjectsQuery, 0, 10)).extracting(ComponentDto::getKey).containsExactly("private-key"); + assertThat(underTest.selectByQuery(dbSession, publicProjectsQuery, 0, 10)).extracting(ComponentDto::getKey).containsExactly("public-key"); + assertThat(underTest.selectByQuery(dbSession, allProjectsQuery, 0, 10)).extracting(ComponentDto::getKey).containsOnly("public-key", "private-key"); } @Test @@ -1609,13 +1584,13 @@ public class ComponentDaoTest { ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto()); ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto()); ComponentQuery query = ComponentQuery.builder().setQualifiers(PROJECT) - .setComponentKeys(newHashSet(sonarqube.getDbKey(), jdk8.getDbKey())).build(); + .setComponentKeys(newHashSet(sonarqube.getKey(), jdk8.getKey())).build(); List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10); - assertThat(result).hasSize(2).extracting(ComponentDto::getDbKey) - .containsExactlyInAnyOrder(sonarqube.getDbKey(), jdk8.getDbKey()) - .doesNotContain(cLang.getDbKey()); + assertThat(result).hasSize(2).extracting(ComponentDto::getKey) + .containsExactlyInAnyOrder(sonarqube.getKey(), jdk8.getKey()) + .doesNotContain(cLang.getKey()); } @Test @@ -1675,11 +1650,11 @@ public class ComponentDaoTest { db.components().insertProjectAndSnapshot(project); ComponentDto module = newModuleDto(MODULE_UUID, project); db.components().insertComponent(module); - ComponentDto fileInProject = newFileDto(project, null, FILE_1_UUID).setDbKey("file-key-1").setName("File One"); + ComponentDto fileInProject = newFileDto(project, null, FILE_1_UUID).setKey("file-key-1").setName("File One"); db.components().insertComponent(fileInProject); - ComponentDto file1InModule = newFileDto(module, null, FILE_2_UUID).setDbKey("file-key-2").setName("File Two"); + ComponentDto file1InModule = newFileDto(module, null, FILE_2_UUID).setKey("file-key-2").setName("File Two"); db.components().insertComponent(file1InModule); - ComponentDto file2InModule = newFileDto(module, null, FILE_3_UUID).setDbKey("file-key-3").setName("File Three"); + ComponentDto file2InModule = newFileDto(module, null, FILE_3_UUID).setKey("file-key-3").setName("File Three"); db.components().insertComponent(file2InModule); db.commit(); @@ -1703,11 +1678,11 @@ public class ComponentDaoTest { db.components().insertProjectAndSnapshot(project); ComponentDto module = newModuleDto(MODULE_UUID, project); db.components().insertComponent(module); - ComponentDto fileInProject = newFileDto(project, null, FILE_1_UUID).setDbKey("file-key-1").setName("File One"); + ComponentDto fileInProject = newFileDto(project, null, FILE_1_UUID).setKey("file-key-1").setName("File One"); db.components().insertComponent(fileInProject); - ComponentDto file1InModule = newFileDto(module, null, FILE_2_UUID).setDbKey("file-key-2").setName("File Two"); + ComponentDto file1InModule = newFileDto(module, null, FILE_2_UUID).setKey("file-key-2").setName("File Two"); db.components().insertComponent(file1InModule); - ComponentDto file2InModule = newFileDto(module, null, FILE_3_UUID).setDbKey("file-key-3").setName("File Three"); + ComponentDto file2InModule = newFileDto(module, null, FILE_3_UUID).setKey("file-key-3").setName("File Three"); db.components().insertComponent(file2InModule); db.commit(); @@ -1818,11 +1793,11 @@ public class ComponentDaoTest { String uuid2 = "uuid2"; String[] uuids = { - db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid1).setPrivate(true)).uuid(), - db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid1).setPrivate(false)).uuid(), - db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid2).setPrivate(true)).uuid(), - db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid2).setPrivate(false)).uuid(), - db.components().insertComponent(newPrivateProjectDto().setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setBranchUuid(uuid1).setPrivate(true)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setBranchUuid(uuid1).setPrivate(false)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setBranchUuid(uuid2).setPrivate(true)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setBranchUuid(uuid2).setPrivate(false)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setRootUuid(uuid1).setBranchUuid("foo").setPrivate(false)).uuid(), }; underTest.setPrivateForRootComponentUuidWithoutAudit(db.getSession(), uuid1, true); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java index b59c8dee9e1..061dbac8515 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java @@ -30,7 +30,7 @@ public class ComponentDtoTest { @Test public void setters_and_getters() { ComponentDto componentDto = new ComponentDto() - .setDbKey("org.struts:struts-core:src/org/struts/RequestContext.java") + .setKey("org.struts:struts-core:src/org/struts/RequestContext.java") .setName("RequestContext.java") .setLongName("org.struts.RequestContext") .setQualifier("FIL") @@ -41,7 +41,7 @@ public class ComponentDtoTest { .setCopyComponentUuid("uuid_5") .setRootUuid("uuid_3"); - assertThat(componentDto.getDbKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); + assertThat(componentDto.getKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); assertThat(componentDto.getBranch()).isNull(); assertThat(componentDto.name()).isEqualTo("RequestContext.java"); assertThat(componentDto.longName()).isEqualTo("org.struts.RequestContext"); @@ -109,26 +109,4 @@ public class ComponentDtoTest { ComponentDto nonRoot = new ComponentDto().setUuidPath(".12.34.56."); assertThat(nonRoot.getUuidPathAsList()).containsExactly("12", "34", "56"); } - - @Test - public void getKey_and_getBranch() { - ComponentDto underTest = new ComponentDto().setDbKey("my_key:BRANCH:my_branch"); - assertThat(underTest.getKey()).isEqualTo("my_key"); - assertThat(underTest.getBranch()).isEqualTo("my_branch"); - - underTest = new ComponentDto().setDbKey("my_key"); - assertThat(underTest.getKey()).isEqualTo("my_key"); - assertThat(underTest.getBranch()).isNull(); - } - - @Test - public void getKey_and_getPullRequest() { - ComponentDto underTest = new ComponentDto().setDbKey("my_key:PULL_REQUEST:pr-123"); - assertThat(underTest.getKey()).isEqualTo("my_key"); - assertThat(underTest.getPullRequest()).isEqualTo("pr-123"); - - underTest = new ComponentDto().setDbKey("my_key"); - assertThat(underTest.getKey()).isEqualTo("my_key"); - assertThat(underTest.getPullRequest()).isNull(); - } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java index 585f9708ddb..e77ed5dd4e9 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java @@ -52,8 +52,7 @@ import static org.sonar.db.component.ComponentTesting.newModuleDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; public class ComponentKeyUpdaterDaoTest { - - + @Rule public DbTester db = DbTester.create(System2.INSTANCE); private AuditPersister auditPersister = mock(AuditPersister.class); @@ -86,13 +85,13 @@ public class ComponentKeyUpdaterDaoTest { public void updateKey_updates_disabled_components() { ComponentDto project = db.components().insertComponent( newPrivateProjectDto("A") - .setDbKey("my_project")); + .setKey("my_project")); ComponentDto directory = db.components().insertComponent( newDirectory(project, "B") - .setDbKey("my_project:directory")); - db.components().insertComponent(newFileDto(project, directory).setDbKey("my_project:directory/file")); - ComponentDto inactiveDirectory = db.components().insertComponent(newDirectory(project, "/inactive_directory").setDbKey("my_project:inactive_directory").setEnabled(false)); - db.components().insertComponent(newFileDto(project, inactiveDirectory).setDbKey("my_project:inactive_directory/file").setEnabled(false)); + .setKey("my_project:directory")); + db.components().insertComponent(newFileDto(project, directory).setKey("my_project:directory/file")); + ComponentDto inactiveDirectory = db.components().insertComponent(newDirectory(project, "/inactive_directory").setKey("my_project:inactive_directory").setEnabled(false)); + db.components().insertComponent(newFileDto(project, inactiveDirectory).setKey("my_project:inactive_directory/file").setEnabled(false)); underTest.updateKey(dbSession, "A", "your_project"); dbSession.commit(); @@ -100,7 +99,7 @@ public class ComponentKeyUpdaterDaoTest { List<ComponentDto> result = dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, "your_project"); assertThat(result) .hasSize(5) - .extracting(ComponentDto::getDbKey) + .extracting(ComponentDto::getKey) .containsOnlyOnce("your_project", "your_project:directory", "your_project:directory/file", "your_project:inactive_directory", "your_project:inactive_directory/file"); } @@ -109,20 +108,20 @@ public class ComponentKeyUpdaterDaoTest { ComponentDto app = db.components().insertPublicProject(); ComponentDto appBranch = db.components().insertProjectBranch(app); ComponentDto appBranchProj1 = appBranch.copy() - .setDbKey(appBranch.getDbKey().replace(BRANCH_KEY_SEPARATOR, "") + "appBranchProj1:BRANCH:1").setUuid("appBranchProj1").setScope(Qualifiers.FILE); + .setKey(appBranch.getKey().replace(BRANCH_KEY_SEPARATOR, "") + "appBranchProj1").setUuid("appBranchProj1").setScope(Qualifiers.FILE); ComponentDto appBranchProj2 = appBranch.copy() - .setDbKey(appBranch.getDbKey().replace(BRANCH_KEY_SEPARATOR, "") + "appBranchProj2:BRANCH:2").setUuid("appBranchProj2").setScope(Qualifiers.FILE); + .setKey(appBranch.getKey().replace(BRANCH_KEY_SEPARATOR, "") + "appBranchProj2").setUuid("appBranchProj2").setScope(Qualifiers.FILE); db.components().insertComponent(appBranchProj1); db.components().insertComponent(appBranchProj2); int branchComponentCount = 3; - String oldBranchKey = appBranch.getDbKey(); + String oldBranchKey = appBranch.getKey(); assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).hasSize(branchComponentCount); String newBranchName = "newKey"; - String newAppBranchKey = ComponentDto.generateBranchKey(app.getDbKey(), newBranchName); - String newAppBranchFragment = app.getDbKey() + newBranchName; - underTest.updateApplicationBranchKey(dbSession, appBranch.uuid(), app.getDbKey(), newBranchName); + String newAppBranchKey = ComponentDto.generateBranchKey(app.getKey(), newBranchName); + String newAppBranchFragment = app.getKey() + newBranchName; + underTest.updateApplicationBranchKey(dbSession, appBranch.uuid(), app.getKey(), newBranchName); assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).isEmpty(); @@ -140,9 +139,9 @@ public class ComponentKeyUpdaterDaoTest { ComponentDto appBranch = db.components().insertProjectBranch(app); db.components().insertProjectBranch(app, b -> b.setKey("newName")); - assertThatThrownBy(() -> underTest.updateApplicationBranchKey(dbSession, appBranch.uuid(), app.getDbKey(), "newName")) + assertThatThrownBy(() -> underTest.updateApplicationBranchKey(dbSession, appBranch.uuid(), app.getKey(), "newName")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage(String.format("Impossible to update key: a component with key \"%s\" already exists.", generateBranchKey(app.getDbKey(), "newName"))); + .hasMessage(String.format("Impossible to update key: a component with key \"%s\" already exists.", generateBranchKey(app.getKey(), "newName"))); } @Test @@ -151,7 +150,7 @@ public class ComponentKeyUpdaterDaoTest { ComponentDto appBranch = db.components().insertProjectBranch(app); db.components().insertProjectBranch(app, b -> b.setKey("newName")); - underTestWithAuditPersister.updateApplicationBranchKey(dbSession, appBranch.uuid(), app.getDbKey(), "newName2"); + underTestWithAuditPersister.updateApplicationBranchKey(dbSession, appBranch.uuid(), app.getKey(), "newName2"); verify(auditPersister, times(1)) .componentKeyBranchUpdate(any(DbSession.class), any(ComponentKeyNewValue.class), anyString()); @@ -168,7 +167,7 @@ public class ComponentKeyUpdaterDaoTest { String oldProjectKey = project.getKey(); assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).hasSize(1); - String oldBranchKey = branch.getDbKey(); + String oldBranchKey = branch.getKey(); assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).hasSize(branchComponentCount); String newProjectKey = "newKey"; @@ -195,7 +194,7 @@ public class ComponentKeyUpdaterDaoTest { String oldProjectKey = project.getKey(); assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).hasSize(1); - String oldBranchKey = pullRequest.getDbKey(); + String oldBranchKey = pullRequest.getKey(); assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).hasSize(branchComponentCount); String newProjectKey = "newKey"; @@ -212,7 +211,7 @@ public class ComponentKeyUpdaterDaoTest { } private ComponentDto prefixDbKeyWithKey(ComponentDto componentDto, String key) { - return componentDto.setDbKey(key + ":" + componentDto.getDbKey()); + return componentDto.setKey(key + ":" + componentDto.getKey()); } @Test @@ -226,9 +225,9 @@ public class ComponentKeyUpdaterDaoTest { @Test public void updateKey_throws_IAE_when_sub_component_key_is_too_long() { - ComponentDto project = newPrivateProjectDto("project-uuid").setDbKey("old-project-key"); + ComponentDto project = newPrivateProjectDto("project-uuid").setKey("old-project-key"); db.components().insertComponent(project); - db.components().insertComponent(newFileDto(project, null).setDbKey("old-project-key:file")); + db.components().insertComponent(newFileDto(project, null).setKey("old-project-key:file")); String newLongProjectKey = Strings.repeat("a", 400); assertThatThrownBy(() -> underTest.updateKey(dbSession, project.uuid(), newLongProjectKey)) @@ -244,7 +243,7 @@ public class ComponentKeyUpdaterDaoTest { @Test public void updateKey_callsAuditPersister() { - db.components().insertComponent(newPrivateProjectDto("A").setDbKey("my_project")); + db.components().insertComponent(newPrivateProjectDto("A").setKey("my_project")); underTestWithAuditPersister.updateKey(dbSession, "A", "your_project"); @@ -258,13 +257,13 @@ public class ComponentKeyUpdaterDaoTest { } private void populateSomeData() { - ComponentDto project1 = db.components().insertPrivateProject(t -> t.setDbKey("org.struts:struts").setUuid("A")); - ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setDbKey("org.struts:struts-core").setUuid("B")); + ComponentDto project1 = db.components().insertPrivateProject(t -> t.setKey("org.struts:struts").setUuid("A")); + ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setKey("org.struts:struts-core").setUuid("B")); ComponentDto directory1 = db.components().insertComponent(newDirectory(module1, "/src/org/struts").setUuid("C")); - db.components().insertComponent(ComponentTesting.newFileDto(module1, directory1).setDbKey("org.struts:struts-core:/src/org/struts/RequestContext.java").setUuid("D")); - ComponentDto module2 = db.components().insertComponent(newModuleDto(project1).setDbKey("org.struts:struts-ui").setUuid("E")); + db.components().insertComponent(ComponentTesting.newFileDto(module1, directory1).setKey("org.struts:struts-core:/src/org/struts/RequestContext.java").setUuid("D")); + ComponentDto module2 = db.components().insertComponent(newModuleDto(project1).setKey("org.struts:struts-ui").setUuid("E")); ComponentDto directory2 = db.components().insertComponent(newDirectory(module2, "/src/org/struts").setUuid("F")); - db.components().insertComponent(ComponentTesting.newFileDto(module2, directory2).setDbKey("org.struts:struts-ui:/src/org/struts/RequestContext.java").setUuid("G")); - ComponentDto project2 = db.components().insertPublicProject(t -> t.setDbKey("foo:struts-core").setUuid("H")); + db.components().insertComponent(ComponentTesting.newFileDto(module2, directory2).setKey("org.struts:struts-ui:/src/org/struts/RequestContext.java").setUuid("G")); + ComponentDto project2 = db.components().insertPublicProject(t -> t.setKey("foo:struts-core").setUuid("H")); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java index 615afb4141f..868fea8df95 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java @@ -125,7 +125,7 @@ public class ScrollForFileMoveComponentDaoTest { List<ComponentAndSource> files = IntStream.range(0, 300 + random.nextInt(500)) .mapToObj(i -> { String qualifier = random.nextBoolean() ? FILE : UNIT_TEST_FILE; - ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project).setDbKey("f_" + i).setQualifier(qualifier)); + ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project).setKey("f_" + i).setQualifier(qualifier)); FileSourceDto fileSource = db.fileSources().insertFileSource(file); return new ComponentAndSource(file, fileSource); }) @@ -233,7 +233,7 @@ public class ScrollForFileMoveComponentDaoTest { private static void verifyFileMoveRowDto(RecordingResultHandler resultHander, ComponentAndSource componentAndSource) { FileMoveRowDto dto = resultHander.getByUuid(componentAndSource.component.uuid()).get(); - assertThat(dto.getKey()).isEqualTo(componentAndSource.component.getDbKey()); + assertThat(dto.getKey()).isEqualTo(componentAndSource.component.getKey()); assertThat(dto.getUuid()).isEqualTo(componentAndSource.component.uuid()); assertThat(dto.getPath()).isEqualTo(componentAndSource.component.path()); assertThat(dto.getLineCount()).isEqualTo(componentAndSource.source.getLineCount()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java index 3ebd0e7d7dc..598248c39a7 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -639,7 +639,7 @@ public class IssueDaoTest { // return module or dir only if has issue with status different from CLOSED allModuleOrDirs .forEach(moduleOrDir -> { - String projectUuid = moduleOrDir.projectUuid(); + String projectUuid = moduleOrDir.branchUuid(); // CLOSED issue => not returned db.issues().insertIssue(t -> t.setProjectUuid(projectUuid).setComponent(moduleOrDir).setStatus(STATUS_CLOSED)); assertThat(underTest.selectModuleAndDirComponentUuidsOfOpenIssuesForProjectUuid(db.getSession(), projectUuid)) @@ -663,7 +663,7 @@ public class IssueDaoTest { // never return project, view, subview, app or file, whatever the issue status Stream.of(project1, file11, application, view, subview, project2, file21) .forEach(neitherModuleNorDir -> { - String projectUuid = neitherModuleNorDir.projectUuid(); + String projectUuid = neitherModuleNorDir.branchUuid(); STATUSES .forEach(status -> { db.issues().insertIssue(t -> t.setProjectUuid(projectUuid).setComponent(neitherModuleNorDir).setStatus(status)); @@ -675,7 +675,7 @@ public class IssueDaoTest { // never return whatever the component if it is disabled allcomponents .forEach(component -> { - String projectUuid = component.projectUuid(); + String projectUuid = component.branchUuid(); // issues for each status => returned if component is dir or module STATUSES @@ -808,8 +808,8 @@ public class IssueDaoTest { private static IssueDto newIssueDto(String key) { IssueDto dto = new IssueDto(); - dto.setComponent(new ComponentDto().setDbKey("struts:Action").setUuid("component-uuid")); - dto.setProject(new ComponentDto().setDbKey("struts").setUuid("project-uuid")); + dto.setComponent(new ComponentDto().setKey("struts:Action").setUuid("component-uuid")); + dto.setProject(new ComponentDto().setKey("struts").setUuid("project-uuid")); dto.setRule(RuleTesting.newRule(RuleKey.of("java", "S001")).setUuid("uuid-200")); dto.setKee(key); dto.setType(2); @@ -834,8 +834,8 @@ public class IssueDaoTest { private void prepareIssuesComponent() { db.rules().insert(RULE.setIsExternal(true)); - ComponentDto projectDto = db.components().insertPrivateProject(t -> t.setUuid(PROJECT_UUID).setDbKey(PROJECT_KEY)); - db.components().insertComponent(newFileDto(projectDto).setUuid(FILE_UUID).setDbKey(FILE_KEY)); + ComponentDto projectDto = db.components().insertPrivateProject(t -> t.setUuid(PROJECT_UUID).setKey(PROJECT_KEY)); + db.components().insertComponent(newFileDto(projectDto).setUuid(FILE_UUID).setKey(FILE_KEY)); } private void prepareTables() { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java index f756a75f13e..c296effa239 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java @@ -486,7 +486,7 @@ public class IssueMapperTest { .setRuleUuid(rule.getUuid()) .setType(rule.getType()) .setComponentUuid(component.uuid()) - .setProjectUuid(component.projectUuid()) + .setProjectUuid(component.branchUuid()) .setStatus(Issue.STATUS_CLOSED) .setIssueCloseTime(issueCloseTime); Arrays.asList(consumers).forEach(c -> c.accept(res)); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java index cfb9d3c6d13..ac04aa4b4ae 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java @@ -721,7 +721,7 @@ public class LiveMeasureDaoTest { } private ComponentDto addProjectWithMeasure(String projectKey, MetricDto metric, double metricValue) { - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey(projectKey)); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey(projectKey)); addMeasureToComponent(project, metric, metricValue,true); return project; } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java index 84d9e502cd6..ce4bbe75132 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java @@ -62,7 +62,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_project_measure() { ComponentDto project = dbTester.components().insertPrivateProject( - c -> c.setDbKey("Project-Key").setName("Project Name"), + c -> c.setKey("Project-Key").setName("Project Name"), p -> p.setTags(newArrayList("platform", "java"))); SnapshotDto analysis = dbTester.components().insertSnapshot(project); @@ -87,7 +87,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_application_measure() { - ComponentDto project = dbTester.components().insertPrivateApplication(c -> c.setDbKey("App-Key").setName("App Name")); + ComponentDto project = dbTester.components().insertPrivateApplication(c -> c.setKey("App-Key").setName("App Name")); SnapshotDto analysis = dbTester.components().insertSnapshot(project); MetricDto metric1 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc")); @@ -110,7 +110,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_project_measure_having_leak() { ComponentDto project = dbTester.components().insertPrivateProject( - c -> c.setDbKey("Project-Key").setName("Project Name"), + c -> c.setKey("Project-Key").setName("Project Name"), p -> p.setTagsString("platform,java")); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines")); dbTester.measures().insertLiveMeasure(project, metric, m -> m.setVariation(10d)); @@ -269,7 +269,7 @@ public class ProjectMeasuresIndexerIteratorTest { ProjectMeasures doc = docsById.get(project1.uuid()); assertThat(doc).isNotNull(); assertThat(doc.getProject().getUuid()).isEqualTo(project1.uuid()); - assertThat(doc.getProject().getKey()).isNotNull().isEqualTo(project1.getDbKey()); + assertThat(doc.getProject().getKey()).isNotNull().isEqualTo(project1.getKey()); assertThat(doc.getProject().getName()).isNotNull().isEqualTo(project1.name()); assertThat(doc.getProject().getAnalysisDate()).isNotNull().isEqualTo(analysis1.getCreatedAt()); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java index 89f9450d68e..6c8fce59e49 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java @@ -173,13 +173,13 @@ public class GroupPermissionDaoWithPersisterTest { private void addGroupPermission() { group = db.users().insertGroup(g -> g.setUuid("guuid").setName("gname")); - project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname").setDbKey("cKey")); + project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname").setKey("cKey")); dto = getGroupPermission(group, project); underTest.insert(dbSession, dto, project, null); } private void addGroupPermissionWithoutGroup() { - project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname").setDbKey("cKey")); + project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname").setKey("cKey")); dto = getGroupPermission(project); underTest.insert(dbSession, dto, project, null); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java index 72b76e9c4bd..aa1c30d884c 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java @@ -224,7 +224,7 @@ public class PortfolioDaoTest { db.components().insertPrivatePortfolioDto("portfolio1"); db.components().insertPrivatePortfolioDto("portfolio2"); db.components().insertPrivatePortfolioDto("portfolio3"); - ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1")); + ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setKey("app1")); portfolioDao.addReference(session, "portfolio1", "portfolio2"); portfolioDao.addReference(session, "portfolio2", "portfolio3"); @@ -240,7 +240,7 @@ public class PortfolioDaoTest { db.components().insertPrivatePortfolioDto("portfolio1"); db.components().insertPrivatePortfolioDto("portfolio2"); db.components().insertPrivatePortfolioDto("portfolio3"); - ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1")); + ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setKey("app1")); portfolioDao.addReference(session, "portfolio1", "portfolio2"); portfolioDao.addReference(session, "portfolio2", "portfolio3"); @@ -259,9 +259,9 @@ public class PortfolioDaoTest { var p1 = db.components().insertPrivatePortfolioDto("portfolio1"); var p2 = db.components().insertPrivatePortfolioDto("portfolio2", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid())); var p3 = db.components().insertPrivatePortfolioDto("portfolio3", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid())); - ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1")); - ProjectDto app2 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app2")); - ProjectDto app3 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app3")); + ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setKey("app1")); + ProjectDto app2 = db.components().insertPrivateApplicationDto(p -> p.setKey("app2")); + ProjectDto app3 = db.components().insertPrivateApplicationDto(p -> p.setKey("app3")); portfolioDao.addReference(session, "portfolio1", app1.getUuid()); portfolioDao.addReference(session, "portfolio2", app2.getUuid()); @@ -282,9 +282,9 @@ public class PortfolioDaoTest { var p1 = db.components().insertPrivatePortfolioDto("portfolio1"); var p2 = db.components().insertPrivatePortfolioDto("portfolio2", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid())); var p3 = db.components().insertPrivatePortfolioDto("portfolio3", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid())); - ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1")); - ProjectDto app2 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app2")); - ProjectDto app3 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app3")); + ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setKey("app1")); + ProjectDto app2 = db.components().insertPrivateApplicationDto(p -> p.setKey("app2")); + ProjectDto app3 = db.components().insertPrivateApplicationDto(p -> p.setKey("app3")); portfolioDao.addReference(session, "portfolio1", app1.getUuid()); portfolioDao.addReference(session, "portfolio2", app2.getUuid()); @@ -316,10 +316,10 @@ public class PortfolioDaoTest { @Test public void selectAllApplicationProjectsBelongToTheSamePortfolio() { var portfolio = db.components().insertPrivatePortfolioDto("portfolio1"); - var app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1")); - var app2 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app2")); - var project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - var project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); + var app1 = db.components().insertPrivateApplicationDto(p -> p.setKey("app1")); + var app2 = db.components().insertPrivateApplicationDto(p -> p.setKey("app2")); + var project1 = db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + var project2 = db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); db.components().addApplicationProject(app1, project1); db.components().addApplicationProject(app2, project2); @@ -353,7 +353,7 @@ public class PortfolioDaoTest { @Test public void select_reference_to_app_by_key() { PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1"); - ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1")); + ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setKey("app1")); db.components().addPortfolioReference(portfolio, app1.getUuid()); assertThat(portfolioDao.selectReferenceToApp(db.getSession(), portfolio.getUuid(), app1.getKey())) @@ -371,7 +371,7 @@ public class PortfolioDaoTest { @Test public void select_reference_to_app_with_branches() { PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1"); - ProjectDto app = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app").setName("app")); + ProjectDto app = db.components().insertPrivateApplicationDto(p -> p.setKey("app").setName("app")); BranchDto branch1 = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true)); BranchDto branch2 = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true)); @@ -391,7 +391,7 @@ public class PortfolioDaoTest { @Test public void select_root_reference_to_app_main_branch() { PortfolioDto portfolio1 = db.components().insertPrivatePortfolioDto("portfolio1"); - ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1")); + ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setKey("app1")); db.components().addPortfolioReference(portfolio1, app1.getUuid()); assertThat(portfolioDao.selectRootOfReferencersToMainBranch(db.getSession(), app1.getUuid())) @@ -399,7 +399,7 @@ public class PortfolioDaoTest { .containsExactly(portfolio1.getKey()); PortfolioDto portfolio2 = db.components().insertPrivatePortfolioDto("portfolio2"); - ProjectDto app2 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app2")); + ProjectDto app2 = db.components().insertPrivateApplicationDto(p -> p.setKey("app2")); db.components().addPortfolioApplicationBranch(portfolio2.getUuid(), app2.getUuid(), app2.getUuid()); assertThat(portfolioDao.selectRootOfReferencersToMainBranch(db.getSession(), app2.getUuid())) @@ -410,7 +410,7 @@ public class PortfolioDaoTest { @Test public void select_root_reference_to_app_with_branches() { PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1"); - ProjectDto app = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app").setName("app")); + ProjectDto app = db.components().insertPrivateApplicationDto(p -> p.setKey("app").setName("app")); BranchDto branch = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true)); db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app.getUuid(), branch.getUuid()); @@ -530,7 +530,7 @@ public class PortfolioDaoTest { @Test public void deleteReferenceBranch() { PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1"); - ProjectDto app = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app").setName("app")); + ProjectDto app = db.components().insertPrivateApplicationDto(p -> p.setKey("app").setName("app")); BranchDto branch1 = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true)); BranchDto branch2 = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true)); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java index e0ec8ed5a57..dd53c201b97 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java @@ -176,7 +176,7 @@ public class InternalComponentPropertiesDaoTest { underTest.insertOrUpdate(dbSession, portfolio2.uuid(), SOME_KEY, "bar"); underTest.insertOrUpdate(dbSession, portfolio3.uuid(), "foo", SOME_VALUE); - assertThat(underTest.selectDbKeys(dbSession, SOME_KEY, SOME_VALUE)).containsOnly(portfolio1.getDbKey()); + assertThat(underTest.selectDbKeys(dbSession, SOME_KEY, SOME_VALUE)).containsOnly(portfolio1.getKey()); } private InternalComponentPropertyDto saveDto() { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index 8f812c2f8ba..40cf19f892a 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -529,7 +529,7 @@ public class PropertiesDaoTest { insertProperty("project.one", "Pone", projectUuid, null, null, projectDto.getKey(), projectDto.name()); insertProperty("project.two", "Ptwo", projectUuid, null, null, projectDto.getKey(), projectDto.name()); - List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey()); + List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getKey()); assertThat(dtos) .hasSize(2); assertThat(findByKey(dtos, "project.one")) @@ -547,7 +547,7 @@ public class PropertiesDaoTest { ComponentDto projectDto = insertPrivateProject("A"); insertProperty("project.one", dbValue, projectDto.uuid(), null, null, projectDto.getKey(), projectDto.name()); - List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey()); + List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getKey()); assertThat(dtos).hasSize(1); assertThat(dtos.iterator().next()) @@ -1316,7 +1316,7 @@ public class PropertiesDaoTest { } private ComponentDto insertPrivateProject(String projectKey) { - return db.components().insertPrivateProject(t -> t.setDbKey(projectKey)); + return db.components().insertPrivateProject(t -> t.setKey(projectKey)); } private static Consumer<UserDto> withEmail(String login) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java index 5700ff9b356..3be16525ec8 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java @@ -210,7 +210,7 @@ public class PurgeCommandsTest { @Test public void deleteProjects() { ComponentDto project = dbTester.components().insertPrivateProject(); - ProjectDto projectDto = dbTester.getDbClient().projectDao().selectProjectByKey(dbTester.getSession(), project.getDbKey()).get(); + ProjectDto projectDto = dbTester.getDbClient().projectDao().selectProjectByKey(dbTester.getSession(), project.getKey()).get(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); SnapshotDto analysis = dbTester.components().insertSnapshot(project); dbTester.events().insertEvent(analysis); @@ -754,7 +754,7 @@ public class PurgeCommandsTest { } private int countComponentOfRoot(ComponentDto projectOrView) { - return dbTester.countSql("select count(1) from components where project_uuid='" + projectOrView.uuid() + "'"); + return dbTester.countSql("select count(1) from components where branch_uuid='" + projectOrView.uuid() + "'"); } private void insertDuplication(ComponentDto project, SnapshotDto analysis) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index a8bbfc379c6..00826d4dbb5 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -1165,7 +1165,7 @@ public class PurgeDaoTest { newConfigurationWith30Days(System2.INSTANCE, project.uuid(), project.uuid(), disabledComponentUuids), purgeListener, new PurgeProfiler()); - assertThat(db.getDbClient().componentDao().selectByProjectUuid(project.uuid(), dbSession)) + assertThat(db.getDbClient().componentDao().selectByBranchUuid(project.uuid(), dbSession)) .extracting("uuid") .containsOnly(project.uuid(), enabledFileWithIssues.uuid(), disabledFileWithIssues.uuid(), enabledFileWithoutIssues.uuid()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java index bdd73a6f3ee..89f6b619d5e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java @@ -65,9 +65,9 @@ public class ProjectQgateAssociationDaoTest { @Test public void select_all_projects_by_query_should_have_deterministic_order() { QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate(); - ComponentDto project1 = db.components().insertPrivateProject(d -> d.setName("p1").setDbKey("key1")); - ComponentDto project2 = db.components().insertPrivateProject(d -> d.setName("p1").setDbKey("key2")); - ComponentDto project3 = db.components().insertPrivateProject(d -> d.setName("p2").setDbKey("key3")); + ComponentDto project1 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key1")); + ComponentDto project2 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key2")); + ComponentDto project3 = db.components().insertPrivateProject(d -> d.setName("p2").setKey("key3")); db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate1); db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate1); db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project3), qualityGate1); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index dee8e09339f..0631c5d3fc3 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -771,8 +771,8 @@ public class QualityProfileDaoTest { assertThat(underTest.selectSelectedProjects(dbSession, profile1, null)) .extracting("projectUuid", "projectKey", "projectName", "profileKey") .containsOnly( - tuple(project1.uuid(), project1.getDbKey(), project1.name(), profile1.getKee()), - tuple(project2.uuid(), project2.getDbKey(), project2.name(), profile1.getKee())); + tuple(project1.uuid(), project1.getKey(), project1.name(), profile1.getKee()), + tuple(project2.uuid(), project2.getKey(), project2.name(), profile1.getKee())); assertThat(underTest.selectSelectedProjects(dbSession, profile1, "ect1")).hasSize(1); assertThat(underTest.selectSelectedProjects(dbSession, profile3, null)).isEmpty(); @@ -796,8 +796,8 @@ public class QualityProfileDaoTest { assertThat(underTest.selectDeselectedProjects(dbSession, profile1, null)) .extracting("projectUuid", "projectKey", "projectName", "profileKey") .containsExactly( - tuple(project2.uuid(), project2.getDbKey(), project2.name(), null), - tuple(project3.uuid(), project3.getDbKey(), project3.name(), null)); + tuple(project2.uuid(), project2.getKey(), project2.name(), null), + tuple(project3.uuid(), project3.getKey(), project3.name(), null)); assertThat(underTest.selectDeselectedProjects(dbSession, profile1, "ect2")).hasSize(1); assertThat(underTest.selectDeselectedProjects(dbSession, profile3, null)).hasSize(3); @@ -822,9 +822,9 @@ public class QualityProfileDaoTest { assertThat(underTest.selectProjectAssociations(dbSession, profile1, null)) .extracting("projectUuid", "projectKey", "projectName", "profileKey") .containsOnly( - tuple(project1.uuid(), project1.getDbKey(), project1.name(), profile1.getKee()), - tuple(project2.uuid(), project2.getDbKey(), project2.name(), null), - tuple(project3.uuid(), project3.getDbKey(), project3.name(), null)); + tuple(project1.uuid(), project1.getKey(), project1.name(), profile1.getKee()), + tuple(project2.uuid(), project2.getKey(), project2.name(), null), + tuple(project3.uuid(), project3.getKey(), project3.name(), null)); assertThat(underTest.selectProjectAssociations(dbSession, profile1, "ect2")).hasSize(1); assertThat(underTest.selectProjectAssociations(dbSession, profile3, null)).hasSize(3); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java index 30b3152793f..5a04f76f638 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java @@ -56,8 +56,8 @@ public class RegulatoryReportDaoTest { public void prepare() { rule = db.rules().insertRule(); hotspotRule = db.rules().insertHotspotRule(); - project = db.components().insertPrivateProject(t -> t.setProjectUuid(PROJECT_UUID).setUuid(PROJECT_UUID).setDbKey(PROJECT_KEY)); - file = db.components().insertComponent(newFileDto(project).setUuid(FILE_UUID).setDbKey(FILE_KEY)); + project = db.components().insertPrivateProject(t -> t.setBranchUuid(PROJECT_UUID).setUuid(PROJECT_UUID).setKey(PROJECT_KEY)); + file = db.components().insertComponent(newFileDto(project).setUuid(FILE_UUID).setKey(FILE_KEY)); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java index 885ed6d3bde..e1b6f37fb6e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java @@ -245,7 +245,7 @@ public class FileSourceDaoTest { .collect(Collectors.toList()); Map<String, FileHashesDto> fileSourcesByUuid = new HashMap<>(); - underTest.scrollFileHashesByProjectUuid(dbSession, project.projectUuid(), result -> fileSourcesByUuid.put(result.getResultObject().getFileUuid(), result.getResultObject())); + underTest.scrollFileHashesByProjectUuid(dbSession, project.branchUuid(), result -> fileSourcesByUuid.put(result.getResultObject().getFileUuid(), result.getResultObject())); assertThat(fileSourcesByUuid).hasSize(files.size()); files.forEach(t -> assertThat(fileSourcesByUuid).containsKey(t.uuid())); @@ -258,7 +258,7 @@ public class FileSourceDaoTest { FileSourceDto inserted = dbTester.fileSources().insertFileSource(file); List<FileHashesDto> fileSources = new ArrayList<>(1); - underTest.scrollFileHashesByProjectUuid(dbSession, project.projectUuid(), result -> fileSources.add(result.getResultObject())); + underTest.scrollFileHashesByProjectUuid(dbSession, project.branchUuid(), result -> fileSources.add(result.getResultObject())); assertThat(fileSources).hasSize(1); FileHashesDto fileSource = fileSources.iterator().next(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTokenDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTokenDaoTest.java index de5d12ba329..78d4bec46a4 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTokenDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTokenDaoTest.java @@ -69,7 +69,7 @@ public class UserTokenDaoTest { @Test public void insert_project_analysis_token() { UserTokenDto projectAnalysisToken = newProjectAnalysisToken(); - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey(projectAnalysisToken.getProjectKey())); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey(projectAnalysisToken.getProjectKey())); underTest.insert(db.getSession(), projectAnalysisToken, "login"); UserTokenDto projectAnalysisTokenFromDb = underTest.selectByTokenHash(db.getSession(), projectAnalysisToken.getTokenHash()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java index 16145d36850..527ed614192 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java @@ -159,7 +159,7 @@ public class WebhookDaoWithPersisterTest { @Test public void deleteProjectWebhooksIsPersisted() { ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(p -> - p.setUuid("puuid").setName("pname").setDbKey("pkey")); + p.setUuid("puuid").setName("pname").setKey("pkey")); webhookDbTester.insertWebhook(projectDto); underTest.deleteByProject(dbSession, projectDto); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java index db56cf6c597..be729322f02 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java @@ -478,7 +478,7 @@ public class ComponentDbTester { @SafeVarargs public final ComponentDto insertProjectBranch(ComponentDto project, Consumer<BranchDto>... dtoPopulators) { // MainBranchProjectUuid will be null if it's a main branch - BranchDto branchDto = ComponentTesting.newBranchDto(firstNonNull(project.getMainBranchProjectUuid(), project.projectUuid()), BRANCH); + BranchDto branchDto = ComponentTesting.newBranchDto(firstNonNull(project.getMainBranchProjectUuid(), project.branchUuid()), BRANCH); Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(branchDto)); return insertProjectBranch(project, branchDto); } @@ -502,7 +502,7 @@ public class ComponentDbTester { public final ComponentDto insertProjectBranch(ComponentDto project, BranchDto branchDto) { // MainBranchProjectUuid will be null if it's a main branch - checkArgument(branchDto.getProjectUuid().equals(firstNonNull(project.getMainBranchProjectUuid(), project.projectUuid()))); + checkArgument(branchDto.getProjectUuid().equals(firstNonNull(project.getMainBranchProjectUuid(), project.branchUuid()))); ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto); insertComponent(branch); dbClient.branchDao().insert(dbSession, branchDto); @@ -518,7 +518,7 @@ public class ComponentDbTester { public static ProjectDto toProjectDto(ComponentDto componentDto, long createTime) { return new ProjectDto() .setUuid(componentDto.uuid()) - .setKey(componentDto.getDbKey()) + .setKey(componentDto.getKey()) .setQualifier(componentDto.qualifier() != null ? componentDto.qualifier() : Qualifiers.PROJECT) .setCreatedAt(createTime) .setUpdatedAt(createTime) @@ -530,8 +530,8 @@ public class ComponentDbTester { public static PortfolioDto toPortfolioDto(ComponentDto componentDto, long createTime) { return new PortfolioDto() .setUuid(componentDto.uuid()) - .setKey(componentDto.getDbKey()) - .setRootUuid(componentDto.projectUuid()) + .setKey(componentDto.getKey()) + .setRootUuid(componentDto.branchUuid()) .setSelectionMode(NONE.name()) .setCreatedAt(createTime) .setUpdatedAt(createTime) diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java index 741fe1ed192..b32970caf9a 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java @@ -34,8 +34,6 @@ import static org.sonar.db.component.ComponentDto.PULL_REQUEST_SEPARATOR; import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT; import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR; import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent; -import static org.sonar.db.component.ComponentDto.generateBranchKey; -import static org.sonar.db.component.ComponentDto.generatePullRequestKey; public class ComponentTesting { @@ -51,7 +49,7 @@ public class ComponentTesting { String filename = "NAME_" + fileUuid; String path = directory != null ? directory.path() + "/" + filename : module.path() + "/" + filename; return newChildComponent(fileUuid, module, directory == null ? module : directory) - .setDbKey(generateKey("FILE_KEY_" + fileUuid, module)) + .setKey("FILE_KEY_" + fileUuid) .setName(filename) .setLongName(path) .setScope(Scopes.FILE) @@ -68,7 +66,7 @@ public class ComponentTesting { public static ComponentDto newDirectory(ComponentDto module, String uuid, String path) { String key = !path.equals("/") ? module.getKey() + ":" + path : module.getKey() + ":/"; return newChildComponent(uuid, module, module) - .setDbKey(generateKey(key, module)) + .setKey(key) .setName(path) .setLongName(path) .setPath(path) @@ -78,7 +76,7 @@ public class ComponentTesting { public static ComponentDto newSubPortfolio(ComponentDto portfolioOrSubPortfolio, String uuid, String key) { return newModuleDto(uuid, portfolioOrSubPortfolio) - .setDbKey(key) + .setKey(key) .setName(key) .setLongName(key) .setScope(Scopes.PROJECT) @@ -94,7 +92,7 @@ public class ComponentTesting { public static ComponentDto newModuleDto(String uuid, ComponentDto parentModuleOrProject) { return newChildComponent(uuid, parentModuleOrProject, parentModuleOrProject) .setModuleUuidPath(parentModuleOrProject.moduleUuidPath() + uuid + UUID_PATH_SEPARATOR) - .setDbKey(generateKey("MODULE_KEY_" + uuid, parentModuleOrProject)) + .setKey("MODULE_KEY_" + uuid) .setName("NAME_" + uuid) .setLongName("LONG_NAME_" + uuid) .setPath("module") @@ -103,19 +101,6 @@ public class ComponentTesting { .setLanguage(null); } - private static String generateKey(String key, ComponentDto parentModuleOrProject) { - String branch = parentModuleOrProject.getBranch(); - if (branch != null) { - return generateBranchKey(key, branch); - } - String pullRequest = parentModuleOrProject.getPullRequest(); - if (pullRequest != null) { - return generatePullRequestKey(key, pullRequest); - } - - return key; - } - public static ComponentDto newModuleDto(ComponentDto subProjectOrProject) { return newModuleDto(Uuids.createFast(), subProjectOrProject); } @@ -140,10 +125,10 @@ public class ComponentTesting { return new ComponentDto() .setUuid(uuid) .setUuidPath(UUID_PATH_OF_ROOT) - .setProjectUuid(uuid) + .setBranchUuid(uuid) .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) .setRootUuid(uuid) - .setDbKey("KEY_" + uuid) + .setKey("KEY_" + uuid) .setName("NAME_" + uuid) .setLongName("LONG_NAME_" + uuid) .setDescription("DESCRIPTION_" + uuid) @@ -177,7 +162,7 @@ public class ComponentTesting { public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { return newChildComponent(uuid, view, view) - .setDbKey(view.getDbKey() + project.getDbKey()) + .setKey(view.getKey() + project.getKey()) .setName(project.name()) .setLongName(project.longName()) .setCopyComponentUuid(project.uuid()) @@ -194,8 +179,8 @@ public class ComponentTesting { return new ComponentDto() .setUuid(uuid) .setUuidPath(formatUuidPathFromParent(parent)) - .setDbKey(uuid) - .setProjectUuid(moduleOrProject.projectUuid()) + .setKey(uuid) + .setBranchUuid(moduleOrProject.branchUuid()) .setRootUuid(moduleOrProject.uuid()) .setModuleUuid(moduleOrProject.uuid()) .setModuleUuidPath(moduleOrProject.moduleUuidPath()) @@ -216,7 +201,7 @@ public class ComponentTesting { } public static BranchDto newBranchDto(ComponentDto project) { - return newBranchDto(project.projectUuid(), BranchType.BRANCH); + return newBranchDto(project.branchUuid(), BranchType.BRANCH); } public static BranchDto newBranchDto(ComponentDto branchComponent, BranchType branchType) { @@ -238,11 +223,11 @@ public class ComponentTesting { return new ComponentDto() .setUuid(uuid) .setUuidPath(UUID_PATH_OF_ROOT) - .setProjectUuid(uuid) + .setBranchUuid(uuid) .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) .setRootUuid(uuid) // name of the branch is not mandatory on the main branch - .setDbKey(branchName != null ? project.getKey() + branchSeparator + branchName : project.getKey()) + .setKey(branchName != null ? project.getKey() + branchSeparator + branchName : project.getKey()) .setMainBranchProjectUuid(project.getUuid()) .setName(project.getName()) .setLongName(project.getName()) @@ -259,16 +244,14 @@ public class ComponentTesting { checkArgument(project.qualifier().equals(Qualifiers.PROJECT) || project.qualifier().equals(Qualifiers.APP)); checkArgument(project.getMainBranchProjectUuid() == null); String branchName = branchDto.getKey(); - String branchSeparator = branchDto.getBranchType() == PULL_REQUEST ? PULL_REQUEST_SEPARATOR : BRANCH_KEY_SEPARATOR; String uuid = branchDto.getUuid(); return new ComponentDto() .setUuid(uuid) .setUuidPath(UUID_PATH_OF_ROOT) - .setProjectUuid(uuid) + .setBranchUuid(uuid) .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) .setRootUuid(uuid) - // name of the branch is not mandatory on the main branch - .setDbKey(branchName != null ? project.getDbKey() + branchSeparator + branchName : project.getKey()) + .setKey(project.getKey()) .setMainBranchProjectUuid(project.uuid()) .setName(project.name()) .setLongName(project.longName()) diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java index ae451bacac6..5de13132e63 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java @@ -32,7 +32,7 @@ public class SnapshotTesting { public static SnapshotDto newAnalysis(ComponentDto rootComponent) { checkNotNull(rootComponent.uuid(), "Project UUID must be set"); - checkArgument(rootComponent.uuid().equals(rootComponent.projectUuid()), "Component is not a tree root"); + checkArgument(rootComponent.uuid().equals(rootComponent.branchUuid()), "Component is not a tree root"); return newAnalysis(rootComponent.uuid()); } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java index a39dee2a830..330f6cbb9e8 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java @@ -70,7 +70,7 @@ public class MeasureTesting { return new LiveMeasureDto() .setMetricUuid(metric.getUuid()) .setComponentUuid(component.uuid()) - .setProjectUuid(component.projectUuid()) + .setProjectUuid(component.branchUuid()) .setData(String.valueOf(cursor++)) .setValue((double) cursor++) .setVariation((double) cursor++); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/source/FileSourceTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/source/FileSourceTester.java index 4206dfdfce0..9175c4ab8f1 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/source/FileSourceTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/source/FileSourceTester.java @@ -45,7 +45,7 @@ public class FileSourceTester { public final FileSourceDto insertFileSource(ComponentDto file, Consumer<FileSourceDto>... dtoPopulators) { FileSourceDto dto = new FileSourceDto() .setUuid(Uuids.createFast()) - .setProjectUuid(file.projectUuid()) + .setProjectUuid(file.branchUuid()) .setFileUuid(file.uuid()) .setSrcHash(randomAlphanumeric(50)) .setDataHash(randomAlphanumeric(50)) @@ -65,7 +65,7 @@ public class FileSourceTester { public final FileSourceDto insertFileSource(ComponentDto file, int numLines, Consumer<FileSourceDto>... dtoPopulators) { FileSourceDto dto = new FileSourceDto() .setUuid(Uuids.createFast()) - .setProjectUuid(file.projectUuid()) + .setProjectUuid(file.branchUuid()) .setFileUuid(file.uuid()) .setSrcHash(randomAlphanumeric(50)) .setDataHash(randomAlphanumeric(50)) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/CreateIndexForComponentsBranchUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/CreateIndexForComponentsBranchUuid.java new file mode 100644 index 00000000000..4640177e3e6 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/CreateIndexForComponentsBranchUuid.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v97; + +import java.sql.Connection; +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; +import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class CreateIndexForComponentsBranchUuid extends DdlChange { + private static final String INDEX_NAME = "components_branch_uuid"; + private static final String TABLE = "components"; + private static final String COLUMN_NAME = "branch_uuid"; + + public CreateIndexForComponentsBranchUuid(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + try (Connection connection = getDatabase().getDataSource().getConnection()) { + createComponentsBranchUuidIndex(context, connection); + } + } + + private static void createComponentsBranchUuidIndex(Context context, Connection connection) { + if (!DatabaseUtils.indexExistsIgnoreCase(TABLE, INDEX_NAME, connection)) { + context.execute(new CreateIndexBuilder() + .setTable(TABLE) + .setName(INDEX_NAME) + .addColumn(COLUMN_NAME) + .setUnique(false) + .build()); + } + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DbVersion97.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DbVersion97.java index 0234783e802..8cfd5e7b247 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DbVersion97.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DbVersion97.java @@ -29,6 +29,12 @@ public class DbVersion97 implements DbVersion { .add(6600, "Add column 'webhook_secret' to 'alm_settings'", AddWebhookSecretToAlmSettingsTable.class) .add(6601, "Drop non unique index on 'uuid' in 'components'", DropNonUniqueIndexForComponentsUuid.class) .add(6602, "Add unique index on 'uuid' in 'components'", CreateUniqueIndexForComponentsUuid.class) + + .add(6603, "Drop index for 'project_uuid' in 'components'", DropIndexForComponentsProjectUuid.class) + .add(6604, "Rename column 'project_uuid' to 'branch_uuid' in 'components'", RenameProjectUuidToBranchUuidInComponents.class) + .add(6605, "Create index for 'branch_uuid' in 'components'", CreateIndexForComponentsBranchUuid.class) + + .add(6606, "Drop index for 'kee' in 'components'", DropIndexForComponentsKey.class) ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsKey.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsKey.java new file mode 100644 index 00000000000..fa97abd6671 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsKey.java @@ -0,0 +1,29 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v97; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropIndexChange; + +public class DropIndexForComponentsKey extends DropIndexChange { + public DropIndexForComponentsKey(Database db) { + super(db, "projects_kee", "components"); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsProjectUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsProjectUuid.java new file mode 100644 index 00000000000..b6d594c2191 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsProjectUuid.java @@ -0,0 +1,29 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v97; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropIndexChange; + +public class DropIndexForComponentsProjectUuid extends DropIndexChange { + public DropIndexForComponentsProjectUuid(Database db) { + super(db, "projects_project_uuid", "components"); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/RenameProjectUuidToBranchUuidInComponents.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/RenameProjectUuidToBranchUuidInComponents.java new file mode 100644 index 00000000000..00b92dc38d9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v97/RenameProjectUuidToBranchUuidInComponents.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v97; + +import java.sql.Connection; +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.RenameColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class RenameProjectUuidToBranchUuidInComponents extends DdlChange { + private static final String TABLE_NAME = "components"; + + private static final VarcharColumnDef columnDefinition = newVarcharColumnDefBuilder() + .setColumnName("branch_uuid") + .setIsNullable(false) + .setLimit(50) + .build(); + + public RenameProjectUuidToBranchUuidInComponents(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + try (Connection connection = getDatabase().getDataSource().getConnection()) { + if (!DatabaseUtils.tableColumnExists(connection, TABLE_NAME, "branch_uuid") && DatabaseUtils.tableColumnExists(connection, TABLE_NAME, "project_uuid")) { + context.execute(new RenameColumnsBuilder(getDialect(), TABLE_NAME) + .renameColumn("project_uuid", columnDefinition) + .build()); + } + } + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v97/CreateIndexForComponentsBranchUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v97/CreateIndexForComponentsBranchUuidTest.java new file mode 100644 index 00000000000..28fdc9a9d51 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v97/CreateIndexForComponentsBranchUuidTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v97; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +public class CreateIndexForComponentsBranchUuidTest { + static final String INDEX_NAME = "components_branch_uuid"; + static final String TABLE = "components"; + static final String COLUMN_NAME = "branch_uuid"; + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexForComponentsBranchUuidTest.class, "schema.sql"); + + private final CreateIndexForComponentsBranchUuid underTest = new CreateIndexForComponentsBranchUuid(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE, INDEX_NAME); + + underTest.execute(); + + db.assertIndex(TABLE, INDEX_NAME, COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + underTest.execute(); + underTest.execute(); + + db.assertIndex(TABLE, INDEX_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsProjectUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsProjectUuidTest.java new file mode 100644 index 00000000000..35e6768538c --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsProjectUuidTest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v97; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static org.sonar.db.CoreDbTester.createForSchema; + +public class DropIndexForComponentsProjectUuidTest { + private static final String TABLE = "components"; + private static final String INDEX = "projects_project_uuid"; + + @Rule + public final CoreDbTester db = createForSchema(DropIndexForComponentsProjectUuidTest.class, "schema.sql"); + + private final DropIndexForComponentsProjectUuid dropIndexForRuleDescSection = new DropIndexForComponentsProjectUuid(db.database()); + + @Test + public void migration_should_drop_unique_index() throws SQLException { + db.assertIndex(TABLE, INDEX, "project_uuid"); + + dropIndexForRuleDescSection.execute(); + + db.assertIndexDoesNotExist(TABLE, INDEX); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + dropIndexForRuleDescSection.execute(); + dropIndexForRuleDescSection.execute(); + + db.assertIndexDoesNotExist(TABLE, INDEX); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v97/RenameProjectUuidToBranchUuidInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v97/RenameProjectUuidToBranchUuidInComponentsTest.java new file mode 100644 index 00000000000..f25fa0dbe17 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v97/RenameProjectUuidToBranchUuidInComponentsTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v97; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static java.sql.Types.VARCHAR; + +public class RenameProjectUuidToBranchUuidInComponentsTest { + private static final String TABLE_NAME = "components"; + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(RenameProjectUuidToBranchUuidInComponentsTest.class, "schema.sql"); + + private final RenameProjectUuidToBranchUuidInComponents underTest = new RenameProjectUuidToBranchUuidInComponents(db.database()); + + @Test + public void type_column_is_not_null() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "branch_uuid", VARCHAR, 50, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + underTest.execute(); + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "branch_uuid", VARCHAR, 50, false); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v97/CreateIndexForComponentsBranchUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v97/CreateIndexForComponentsBranchUuidTest/schema.sql new file mode 100644 index 00000000000..4f56aea53a9 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v97/CreateIndexForComponentsBranchUuidTest/schema.sql @@ -0,0 +1,41 @@ + +CREATE TABLE "COMPONENTS"( + "UUID" CHARACTER VARYING(50) NOT NULL, + "KEE" CHARACTER VARYING(1000), + "DEPRECATED_KEE" CHARACTER VARYING(400), + "NAME" CHARACTER VARYING(2000), + "LONG_NAME" CHARACTER VARYING(2000), + "DESCRIPTION" CHARACTER VARYING(2000), + "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL, + "SCOPE" CHARACTER VARYING(3), + "QUALIFIER" CHARACTER VARYING(10), + "PRIVATE" BOOLEAN NOT NULL, + "ROOT_UUID" CHARACTER VARYING(50) NOT NULL, + "LANGUAGE" CHARACTER VARYING(20), + "COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "PATH" CHARACTER VARYING(2000), + "UUID_PATH" CHARACTER VARYING(1500) NOT NULL, + "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL, + "MODULE_UUID" CHARACTER VARYING(50), + "MODULE_UUID_PATH" CHARACTER VARYING(1500), + "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50), + "B_CHANGED" BOOLEAN, + "B_NAME" CHARACTER VARYING(500), + "B_LONG_NAME" CHARACTER VARYING(500), + "B_DESCRIPTION" CHARACTER VARYING(2000), + "B_ENABLED" BOOLEAN, + "B_QUALIFIER" CHARACTER VARYING(10), + "B_LANGUAGE" CHARACTER VARYING(20), + "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "B_PATH" CHARACTER VARYING(2000), + "B_UUID_PATH" CHARACTER VARYING(1500), + "B_MODULE_UUID" CHARACTER VARYING(50), + "B_MODULE_UUID_PATH" CHARACTER VARYING(1500), + "CREATED_AT" TIMESTAMP +); +CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE" NULLS FIRST); +CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID" NULLS FIRST); +CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST); +CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST); +CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST); +CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsProjectUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsProjectUuidTest/schema.sql new file mode 100644 index 00000000000..fc8a4a7a9d2 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v97/DropIndexForComponentsProjectUuidTest/schema.sql @@ -0,0 +1,41 @@ +CREATE TABLE "COMPONENTS"( + "UUID" CHARACTER VARYING(50) NOT NULL, + "KEE" CHARACTER VARYING(1000), + "DEPRECATED_KEE" CHARACTER VARYING(400), + "NAME" CHARACTER VARYING(2000), + "LONG_NAME" CHARACTER VARYING(2000), + "DESCRIPTION" CHARACTER VARYING(2000), + "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL, + "SCOPE" CHARACTER VARYING(3), + "QUALIFIER" CHARACTER VARYING(10), + "PRIVATE" BOOLEAN NOT NULL, + "ROOT_UUID" CHARACTER VARYING(50) NOT NULL, + "LANGUAGE" CHARACTER VARYING(20), + "COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "PATH" CHARACTER VARYING(2000), + "UUID_PATH" CHARACTER VARYING(1500) NOT NULL, + "PROJECT_UUID" CHARACTER VARYING(50) NOT NULL, + "MODULE_UUID" CHARACTER VARYING(50), + "MODULE_UUID_PATH" CHARACTER VARYING(1500), + "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50), + "B_CHANGED" BOOLEAN, + "B_NAME" CHARACTER VARYING(500), + "B_LONG_NAME" CHARACTER VARYING(500), + "B_DESCRIPTION" CHARACTER VARYING(2000), + "B_ENABLED" BOOLEAN, + "B_QUALIFIER" CHARACTER VARYING(10), + "B_LANGUAGE" CHARACTER VARYING(20), + "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "B_PATH" CHARACTER VARYING(2000), + "B_UUID_PATH" CHARACTER VARYING(1500), + "B_MODULE_UUID" CHARACTER VARYING(50), + "B_MODULE_UUID_PATH" CHARACTER VARYING(1500), + "CREATED_AT" TIMESTAMP +); +CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE" NULLS FIRST); +CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID" NULLS FIRST); +CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID" NULLS FIRST); +CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST); +CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST); +CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST); +CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v97/RenameProjectUuidToBranchUuidInComponentsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v97/RenameProjectUuidToBranchUuidInComponentsTest/schema.sql new file mode 100644 index 00000000000..8373917f80e --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v97/RenameProjectUuidToBranchUuidInComponentsTest/schema.sql @@ -0,0 +1,41 @@ + +CREATE TABLE "COMPONENTS"( + "UUID" CHARACTER VARYING(50) NOT NULL, + "KEE" CHARACTER VARYING(1000), + "DEPRECATED_KEE" CHARACTER VARYING(400), + "NAME" CHARACTER VARYING(2000), + "LONG_NAME" CHARACTER VARYING(2000), + "DESCRIPTION" CHARACTER VARYING(2000), + "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL, + "SCOPE" CHARACTER VARYING(3), + "QUALIFIER" CHARACTER VARYING(10), + "PRIVATE" BOOLEAN NOT NULL, + "ROOT_UUID" CHARACTER VARYING(50) NOT NULL, + "LANGUAGE" CHARACTER VARYING(20), + "COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "PATH" CHARACTER VARYING(2000), + "UUID_PATH" CHARACTER VARYING(1500) NOT NULL, + "PROJECT_UUID" CHARACTER VARYING(50) NOT NULL, + "MODULE_UUID" CHARACTER VARYING(50), + "MODULE_UUID_PATH" CHARACTER VARYING(1500), + "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50), + "B_CHANGED" BOOLEAN, + "B_NAME" CHARACTER VARYING(500), + "B_LONG_NAME" CHARACTER VARYING(500), + "B_DESCRIPTION" CHARACTER VARYING(2000), + "B_ENABLED" BOOLEAN, + "B_QUALIFIER" CHARACTER VARYING(10), + "B_LANGUAGE" CHARACTER VARYING(20), + "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50), + "B_PATH" CHARACTER VARYING(2000), + "B_UUID_PATH" CHARACTER VARYING(1500), + "B_MODULE_UUID" CHARACTER VARYING(50), + "B_MODULE_UUID_PATH" CHARACTER VARYING(1500), + "CREATED_AT" TIMESTAMP +); +CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE" NULLS FIRST); +CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID" NULLS FIRST); +CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST); +CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID" NULLS FIRST); +CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST); +CREATE INDEX "IDX_MAIN_BRANCH_PRJ_UUID" ON "COMPONENTS"("MAIN_BRANCH_PROJECT_UUID" NULLS FIRST); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java index 2d1c7a26cf4..94054fde773 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java @@ -127,7 +127,7 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe dbClient.componentDao().scrollForIndexing(dbSession, branchUuid, context -> { ComponentDto dto = context.getResultObject(); bulkIndexer.add(toDocument(dto).toIndexRequest()); - remaining.remove(dto.projectUuid()); + remaining.remove(dto.branchUuid()); }); } @@ -185,8 +185,8 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe return new ComponentDoc() .setId(component.uuid()) .setName(component.name()) - .setKey(component.getDbKey()) - .setProjectUuid(component.projectUuid()) + .setKey(component.getKey()) + .setProjectUuid(component.branchUuid()) .setQualifier(component.qualifier()); } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/ProjectIndexers.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/ProjectIndexers.java index ee832cd2e13..e19163b9e07 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/ProjectIndexers.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/ProjectIndexers.java @@ -46,7 +46,7 @@ public interface ProjectIndexers { default void commitAndIndexComponents(DbSession dbSession, Collection<ComponentDto> projects, ProjectIndexer.Cause cause) { Collection<String> projectUuids = projects.stream() - .map(ComponentDto::projectUuid) + .map(ComponentDto::branchUuid) .collect(MoreCollectors.toSet(projects.size())); commitAndIndexByProjectUuids(dbSession, projectUuids, cause); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java b/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java index eb9ee198e5e..2e27ce531f5 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java @@ -51,7 +51,7 @@ public class FavoriteUpdater { .setUserUuid(userUuid) .setComponentUuid(componentDto.uuid()) .build(), dbSession); - checkArgument(existingFavoriteOnComponent.isEmpty(), "Component '%s' is already a favorite", componentDto.getDbKey()); + checkArgument(existingFavoriteOnComponent.isEmpty(), "Component '%s' is already a favorite", componentDto.getKey()); List<PropertyDto> existingFavorites = dbClient.propertiesDao().selectByKeyAndUserUuidAndComponentQualifier(dbSession, PROP_FAVORITE_KEY, userUuid, componentDto.qualifier()); if (existingFavorites.size() >= 100) { @@ -81,6 +81,6 @@ public class FavoriteUpdater { .setComponentUuid(component.uuid()) .setUserUuid(userUuid), userLogin, component.getKey(), component.name(), component.qualifier()); - checkArgument(result == 1, "Component '%s' is not a favorite", component.getDbKey()); + checkArgument(result == 1, "Component '%s' is not a favorite", component.getKey()); } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java index f636672025f..308f6a21d97 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java @@ -111,7 +111,7 @@ public class IssueIndexer implements ProjectIndexer, NeedAuthorizationIndexer { @Override public void indexOnAnalysis(String branchUuid) { - try (IssueIterator issues = issueIteratorFactory.createForProject(branchUuid)) { + try (IssueIterator issues = issueIteratorFactory.createForBranch(branchUuid)) { doIndex(issues, Size.REGULAR, IndexingListener.FAIL_ON_ERROR); } } @@ -217,7 +217,7 @@ public class IssueIndexer implements ProjectIndexer, NeedAuthorizationIndexer { for (String projectUuid : itemsByProjectUuid.keySet()) { // TODO support loading of multiple projects in a single SQL request - try (IssueIterator issues = issueIteratorFactory.createForProject(projectUuid)) { + try (IssueIterator issues = issueIteratorFactory.createForBranch(projectUuid)) { if (issues.hasNext()) { do { IssueDoc doc = issues.next(); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorFactory.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorFactory.java index 446972d8b8e..a1ebd01b125 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorFactory.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorFactory.java @@ -32,11 +32,11 @@ public class IssueIteratorFactory { } public IssueIterator createForAll() { - return createForProject(null); + return createForBranch(null); } - public IssueIterator createForProject(@Nullable String projectUuid) { - return new IssueIteratorForSingleChunk(dbClient, projectUuid, null); + public IssueIterator createForBranch(@Nullable String branchUuid) { + return new IssueIteratorForSingleChunk(dbClient, branchUuid, null); } public IssueIterator createForIssueKeys(Collection<String> issueKeys) { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java index d2b3715304d..0427d887552 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java @@ -74,7 +74,7 @@ class IssueIteratorForSingleChunk implements IssueIterator { "c.module_uuid_path", "c.path", "c.scope", - "c.project_uuid", + "c.branch_uuid", "c.main_branch_project_uuid", // column 21 @@ -91,17 +91,16 @@ class IssueIteratorForSingleChunk implements IssueIterator { private static final String SQL_NEW_CODE_JOIN = "left join new_code_reference_issues n on n.issue_key = i.kee "; - private static final String PROJECT_FILTER = " and c.project_uuid = ? and i.project_uuid = ? "; + private static final String BRANCH_FILTER = " and c.branch_uuid = ? and i.project_uuid = ? "; private static final String ISSUE_KEY_FILTER_PREFIX = " and i.kee in ("; private static final String ISSUE_KEY_FILTER_SUFFIX = ") "; static final Splitter TAGS_SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings(); - static final Splitter MODULE_PATH_SPLITTER = Splitter.on('.').trimResults().omitEmptyStrings(); private final DbSession session; @CheckForNull - private final String projectUuid; + private final String branchUuid; @CheckForNull private final Collection<String> issueKeys; @@ -109,10 +108,10 @@ class IssueIteratorForSingleChunk implements IssueIterator { private final PreparedStatement stmt; private final ResultSetIterator<IssueDoc> iterator; - IssueIteratorForSingleChunk(DbClient dbClient, @Nullable String projectUuid, @Nullable Collection<String> issueKeys) { + IssueIteratorForSingleChunk(DbClient dbClient, @Nullable String branchUuid, @Nullable Collection<String> issueKeys) { checkArgument(issueKeys == null || issueKeys.size() <= DatabaseUtils.PARTITION_SIZE_FOR_ORACLE, "Cannot search for more than " + DatabaseUtils.PARTITION_SIZE_FOR_ORACLE + " issue keys at once. Please provide the keys in smaller chunks."); - this.projectUuid = projectUuid; + this.branchUuid = branchUuid; this.issueKeys = issueKeys; this.session = dbClient.openSession(false); @@ -148,7 +147,7 @@ class IssueIteratorForSingleChunk implements IssueIterator { private String createSql() { String sql = SQL_ALL; - sql += projectUuid == null ? "" : PROJECT_FILTER; + sql += branchUuid == null ? "" : BRANCH_FILTER; if (issueKeys != null && !issueKeys.isEmpty()) { sql += ISSUE_KEY_FILTER_PREFIX; sql += IntStream.range(0, issueKeys.size()).mapToObj(i -> "?").collect(Collectors.joining(",")); @@ -160,10 +159,10 @@ class IssueIteratorForSingleChunk implements IssueIterator { private void setParameters(PreparedStatement stmt) throws SQLException { int index = 1; - if (projectUuid != null) { - stmt.setString(index, projectUuid); + if (branchUuid != null) { + stmt.setString(index, branchUuid); index++; - stmt.setString(index, projectUuid); + stmt.setString(index, branchUuid); index++; } if (issueKeys != null) { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/setting/ProjectConfigurationLoaderImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/setting/ProjectConfigurationLoaderImpl.java index 8470d57f035..fc7c5b17148 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/setting/ProjectConfigurationLoaderImpl.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/setting/ProjectConfigurationLoaderImpl.java @@ -48,13 +48,13 @@ public class ProjectConfigurationLoaderImpl implements ProjectConfigurationLoade Map<String, ChildSettings> mainBranchSettingsByDbKey = loadMainBranchConfigurations(dbSession, mainBranchDbKeys); return projects.stream() .collect(uniqueIndex(ComponentDto::uuid, component -> { - if (component.getDbKey().equals(component.getKey())) { + if (component.getKey().equals(component.getKey())) { return mainBranchSettingsByDbKey.get(component.getKey()).asConfiguration(); } ChildSettings settings = new ChildSettings(mainBranchSettingsByDbKey.get(component.getKey())); dbClient.propertiesDao() - .selectProjectProperties(dbSession, component.getDbKey()) + .selectProjectProperties(dbSession, component.getKey()) .forEach(property -> settings.setProperty(property.getKey(), property.getValue())); return settings.asConfiguration(); })); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewIndexer.java index d3a895cc99c..fd7cce98adf 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewIndexer.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewIndexer.java @@ -30,7 +30,7 @@ import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.UuidWithProjectUuidDto; +import org.sonar.db.component.UuidWithBranchUuidDto; import org.sonar.db.es.EsQueueDto; import org.sonar.server.es.BulkIndexer; import org.sonar.server.es.BulkIndexer.Size; @@ -71,8 +71,8 @@ public class ViewIndexer implements ResilientIndexer { private void indexAll(Size bulkSize) { try (DbSession dbSession = dbClient.openSession(false)) { Map<String, String> viewAndProjectViewUuidMap = new HashMap<>(); - for (UuidWithProjectUuidDto uuidWithProjectUuidDto : dbClient.componentDao().selectAllViewsAndSubViews(dbSession)) { - viewAndProjectViewUuidMap.put(uuidWithProjectUuidDto.getUuid(), uuidWithProjectUuidDto.getProjectUuid()); + for (UuidWithBranchUuidDto uuidWithBranchUuidDto : dbClient.componentDao().selectAllViewsAndSubViews(dbSession)) { + viewAndProjectViewUuidMap.put(uuidWithBranchUuidDto.getUuid(), uuidWithBranchUuidDto.getBranchUuid()); } index(dbSession, viewAndProjectViewUuidMap, false, bulkSize); } @@ -88,7 +88,7 @@ public class ViewIndexer implements ResilientIndexer { try (DbSession dbSession = dbClient.openSession(false)) { Map<String, String> viewAndProjectViewUuidMap = new HashMap<>(); for (ComponentDto viewOrSubView : dbClient.componentDao().selectEnabledDescendantModules(dbSession, rootViewUuid)) { - viewAndProjectViewUuidMap.put(viewOrSubView.uuid(), viewOrSubView.projectUuid()); + viewAndProjectViewUuidMap.put(viewOrSubView.uuid(), viewOrSubView.branchUuid()); } index(dbSession, viewAndProjectViewUuidMap, true, Size.REGULAR); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java index faa055d3767..34fe87ab95d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java @@ -102,8 +102,8 @@ public class ComponentIndexerTest { assertThatIndexContainsOnly(project); ComponentDoc doc = es.getDocuments(TYPE_COMPONENT, ComponentDoc.class).get(0); assertThat(doc.getId()).isEqualTo(project.uuid()); - assertThat(doc.getKey()).isEqualTo(project.getDbKey()); - assertThat(doc.getProjectUuid()).isEqualTo(project.projectUuid()); + assertThat(doc.getKey()).isEqualTo(project.getKey()); + assertThat(doc.getProjectUuid()).isEqualTo(project.branchUuid()); assertThat(doc.getName()).isEqualTo(project.name()); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java index c3fc3cf0b7b..f77fa99816d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java @@ -85,7 +85,7 @@ public class IssueIteratorFactoryTest { assertThat(issue.line()).isEqualTo(444); assertThat(issue.ruleUuid()).isEqualTo(rule.getUuid()); assertThat(issue.componentUuid()).isEqualTo(file.uuid()); - assertThat(issue.projectUuid()).isEqualTo(file.projectUuid()); + assertThat(issue.projectUuid()).isEqualTo(file.branchUuid()); assertThat(issue.modulePath()).isEqualTo(file.moduleUuidPath()); assertThat(issue.directoryPath()).isEqualTo("src/main/java"); assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java"); @@ -142,11 +142,11 @@ public class IssueIteratorFactoryTest { .map(project2Component -> dbTester.issues().insert(rule, project2, project2Component).getKey()) .toArray(String[]::new); - assertThat(issuesByKey(factory -> factory.createForProject(project1.uuid())).keySet()) + assertThat(issuesByKey(factory -> factory.createForBranch(project1.uuid())).keySet()) .containsOnly(project1IssueKeys); - assertThat(issuesByKey(factory -> factory.createForProject(project2.uuid())).keySet()) + assertThat(issuesByKey(factory -> factory.createForBranch(project2.uuid())).keySet()) .containsOnly(project2IssueKeys); - assertThat(issuesByKey(factory -> factory.createForProject("does not exist"))) + assertThat(issuesByKey(factory -> factory.createForBranch("does not exist"))) .isEmpty(); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ProjectConfigurationLoaderImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ProjectConfigurationLoaderImplTest.java index bac6649e5c8..359a03dc299 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ProjectConfigurationLoaderImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ProjectConfigurationLoaderImplTest.java @@ -182,7 +182,7 @@ public class ProjectConfigurationLoaderImplTest { } private ComponentDto newComponentDto(String componentDbKey, String componentUuid) { - return new ComponentDto().setDbKey(componentDbKey).setUuid(componentUuid); + return new ComponentDto().setKey(componentDbKey).setUuid(componentUuid); } private PropertyDto newPropertyDto(String projectKey1, String projectValue1) { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java index e1ac645ec30..301369b93bb 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java @@ -189,14 +189,14 @@ public class ViewIndexerTest { @Test public void index_application_branch() { - ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setDbKey("app")); + ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app")); ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1")); ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2")); - ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("prj1")); + ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1")); ComponentDto project1Branch = db.components().insertProjectBranch(project1); - ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("prj2")); + ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2")); ComponentDto project2Branch = db.components().insertProjectBranch(project2); - ComponentDto project3 = db.components().insertPrivateProject(p -> p.setDbKey("prj3")); + ComponentDto project3 = db.components().insertPrivateProject(p -> p.setKey("prj3")); ComponentDto project3Branch = db.components().insertProjectBranch(project3); db.components().insertComponent(newProjectCopy(project1Branch, applicationBranch1)); db.components().insertComponent(newProjectCopy(project2Branch, applicationBranch1)); diff --git a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java index d67cd23a41c..8c5144937d9 100644 --- a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java +++ b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java @@ -45,10 +45,10 @@ public class IssueDocTesting { String mainBranchProjectUuid = componentDto.getMainBranchProjectUuid(); return newDoc() .setKey(key) - .setBranchUuid(componentDto.projectUuid()) + .setBranchUuid(componentDto.branchUuid()) .setComponentUuid(componentDto.uuid()) .setModuleUuidPath(componentDto.moduleUuidPath()) - .setProjectUuid(mainBranchProjectUuid == null ? componentDto.projectUuid() : mainBranchProjectUuid) + .setProjectUuid(mainBranchProjectUuid == null ? componentDto.branchUuid() : mainBranchProjectUuid) // File path make no sens on modules and projects .setFilePath(!componentDto.scope().equals(Scopes.PROJECT) ? componentDto.path() : null) .setIsMainBranch(mainBranchProjectUuid == null) diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java index 58702dac6e8..503ac3a7ad1 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java @@ -89,7 +89,7 @@ public abstract class AbstractUserSession implements UserSession { @Override public final boolean hasComponentPermission(String permission, ComponentDto component) { - String projectUuid = defaultString(component.getMainBranchProjectUuid(), component.projectUuid()); + String projectUuid = defaultString(component.getMainBranchProjectUuid(), component.branchUuid()); return hasProjectUuidPermission(permission, projectUuid); } @@ -105,7 +105,7 @@ public abstract class AbstractUserSession implements UserSession { @Override public final boolean hasChildProjectsPermission(String permission, ComponentDto component) { - String applicationUuid = defaultString(component.getMainBranchProjectUuid(), component.projectUuid()); + String applicationUuid = defaultString(component.getMainBranchProjectUuid(), component.branchUuid()); return hasChildProjectsPermission(permission, applicationUuid); } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ServerUserSession.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ServerUserSession.java index 80ec73f6257..a826f6fdda0 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ServerUserSession.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ServerUserSession.java @@ -152,7 +152,7 @@ public class ServerUserSession extends AbstractUserSession { } // if component is part of a branch, then permissions must be // checked on the project (represented by its main branch) - projectUuid = defaultIfEmpty(component.get().getMainBranchProjectUuid(), component.get().projectUuid()); + projectUuid = defaultIfEmpty(component.get().getMainBranchProjectUuid(), component.get().branchUuid()); projectUuidByComponentUuid.put(componentUuid, projectUuid); return of(projectUuid); } @@ -294,14 +294,14 @@ public class ServerUserSession extends AbstractUserSession { protected List<ComponentDto> doKeepAuthorizedComponents(String permission, Collection<ComponentDto> components) { try (DbSession dbSession = dbClient.openSession(false)) { Set<String> projectUuids = components.stream() - .map(c -> defaultIfEmpty(c.getMainBranchProjectUuid(), c.projectUuid())) + .map(c -> defaultIfEmpty(c.getMainBranchProjectUuid(), c.branchUuid())) .collect(MoreCollectors.toSet(components.size())); Map<String, ComponentDto> originalComponents = findComponentsByCopyComponentUuid(components, dbSession); Set<String> originalComponentsProjectUuids = originalComponents.values().stream() - .map(c -> defaultIfEmpty(c.getMainBranchProjectUuid(), c.projectUuid())) + .map(c -> defaultIfEmpty(c.getMainBranchProjectUuid(), c.branchUuid())) .collect(MoreCollectors.toSet(components.size())); Set<String> allProjectUuids = new HashSet<>(projectUuids); @@ -313,10 +313,10 @@ public class ServerUserSession extends AbstractUserSession { .filter(c -> { if (c.getCopyComponentUuid() != null) { var componentDto = originalComponents.get(c.getCopyComponentUuid()); - return componentDto != null && authorizedProjectUuids.contains(defaultIfEmpty(componentDto.getMainBranchProjectUuid(), componentDto.projectUuid())); + return componentDto != null && authorizedProjectUuids.contains(defaultIfEmpty(componentDto.getMainBranchProjectUuid(), componentDto.branchUuid())); } - return authorizedProjectUuids.contains(c.projectUuid()) || authorizedProjectUuids.contains( + return authorizedProjectUuids.contains(c.branchUuid()) || authorizedProjectUuids.contains( c.getMainBranchProjectUuid()); }) .collect(MoreCollectors.toList(components.size())); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java index f1fc01c2a3c..b7fe10de148 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.user; -import java.util.Arrays; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -125,7 +124,7 @@ public class ThreadLocalUserSessionTest { .setGroups(group); ProjectDto subProjectDto = new ProjectDto().setQualifier(Qualifiers.PROJECT).setUuid("subproject-uuid"); - ComponentDto applicationAsComponentDto = new ComponentDto().setQualifier(Qualifiers.APP).setUuid("application-component-uuid").setProjectUuid("application-project-uuid"); + ComponentDto applicationAsComponentDto = new ComponentDto().setQualifier(Qualifiers.APP).setUuid("application-component-uuid").setBranchUuid("application-project-uuid"); ProjectDto applicationAsProjectDto = new ProjectDto().setQualifier(Qualifiers.APP).setUuid("application-project-uuid"); expected.registerProjects(subProjectDto); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/TokenUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/TokenUserSessionTest.java index 43c1b394648..c8f3a890239 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/TokenUserSessionTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/TokenUserSessionTest.java @@ -68,8 +68,8 @@ public class TokenUserSessionTest { TokenUserSession userSession = mockTokenUserSession(user); - assertThat(userSession.hasProjectUuidPermission(SCAN, project1.projectUuid())).isTrue(); - assertThat(userSession.hasProjectUuidPermission(SCAN, project2.projectUuid())).isFalse(); + assertThat(userSession.hasProjectUuidPermission(SCAN, project1.branchUuid())).isTrue(); + assertThat(userSession.hasProjectUuidPermission(SCAN, project2.branchUuid())).isFalse(); } @Test @@ -84,8 +84,8 @@ public class TokenUserSessionTest { TokenUserSession userSession = mockProjectAnalysisTokenUserSession(user,project1); - assertThat(userSession.hasProjectUuidPermission(SCAN, project1.projectUuid())).isTrue(); - assertThat(userSession.hasProjectUuidPermission(SCAN, project2.projectUuid())).isFalse(); + assertThat(userSession.hasProjectUuidPermission(SCAN, project1.branchUuid())).isTrue(); + assertThat(userSession.hasProjectUuidPermission(SCAN, project2.branchUuid())).isFalse(); } @Test @@ -99,8 +99,8 @@ public class TokenUserSessionTest { TokenUserSession userSession = mockProjectAnalysisTokenUserSession(user,project1); - assertThat(userSession.hasProjectUuidPermission(SCAN, project1.projectUuid())).isTrue(); - assertThat(userSession.hasProjectUuidPermission(SCAN, project2.projectUuid())).isFalse(); + assertThat(userSession.hasProjectUuidPermission(SCAN, project1.branchUuid())).isTrue(); + assertThat(userSession.hasProjectUuidPermission(SCAN, project2.branchUuid())).isFalse(); } @Test @@ -140,7 +140,7 @@ public class TokenUserSessionTest { TokenUserSession userSession = mockGlobalAnalysisTokenUserSession(user); - assertThat(userSession.hasProjectUuidPermission(SCAN, project1.projectUuid())).isFalse(); + assertThat(userSession.hasProjectUuidPermission(SCAN, project1.branchUuid())).isFalse(); assertThat(userSession.hasPermission(GlobalPermission.SCAN)).isTrue(); } @@ -205,7 +205,7 @@ public class TokenUserSessionTest { userTokenDto.setUserUuid("userUid"); userTokenDto.setProjectKey(componentDto.getKey()); userTokenDto.setProjectName(componentDto.name()); - userTokenDto.setProjectUuid(componentDto.projectUuid()); + userTokenDto.setProjectUuid(componentDto.branchUuid()); return userTokenDto; } diff --git a/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/AbstractMockUserSession.java b/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/AbstractMockUserSession.java index ed2cf0c2ac1..c4ae33eb236 100644 --- a/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/AbstractMockUserSession.java +++ b/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/AbstractMockUserSession.java @@ -71,13 +71,13 @@ public abstract class AbstractMockUserSession<T extends AbstractMockUserSession> public T registerComponents(ComponentDto... components) { Arrays.stream(components) .forEach(component -> { - if (component.projectUuid().equals(component.uuid()) && !component.isPrivate()) { + if (component.branchUuid().equals(component.uuid()) && !component.isPrivate()) { this.projectUuidByPermission.put(UserRole.USER, component.uuid()); this.projectUuidByPermission.put(UserRole.CODEVIEWER, component.uuid()); this.projectPermissions.add(UserRole.USER); this.projectPermissions.add(UserRole.CODEVIEWER); } - this.projectUuidByComponentUuid.put(component.uuid(), component.projectUuid()); + this.projectUuidByComponentUuid.put(component.uuid(), component.branchUuid()); }); return clazz.cast(this); } @@ -156,7 +156,7 @@ public abstract class AbstractMockUserSession<T extends AbstractMockUserSession> registerComponents(components); this.projectPermissions.add(permission); Arrays.stream(components) - .forEach(component -> this.projectUuidByPermission.put(permission, component.projectUuid())); + .forEach(component -> this.projectUuidByPermission.put(permission, component.branchUuid())); return clazz.cast(this); } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/project/ProjectQGChangeEventListenerTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/project/ProjectQGChangeEventListenerTest.java index f85417da4ea..debbba64ed1 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/project/ProjectQGChangeEventListenerTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/project/ProjectQGChangeEventListenerTest.java @@ -137,7 +137,7 @@ public class ProjectQGChangeEventListenerTest { ComponentDto projectComponentDto = new ComponentDto(); projectComponentDto.setQualifier("TRK"); projectComponentDto.setUuid("uuid"); - when(componentDao.selectByProjectUuid(anyString(), any())).thenReturn(List.of(projectComponentDto)); + when(componentDao.selectByBranchUuid(anyString(), any())).thenReturn(List.of(projectComponentDto)); underTest.onIssueChanges(qualityGateEvent, Set.of()); diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java index 7c8e6d0743e..e1f6d21285e 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java @@ -100,7 +100,7 @@ public class IssueQueryFactory { .filter(t -> t != RuleType.SECURITY_HOTSPOT) .map(Enum::name) .collect(MoreCollectors.toSet(RuleType.values().length - 1)); - private static final ComponentDto UNKNOWN_COMPONENT = new ComponentDto().setUuid(UNKNOWN).setProjectUuid(UNKNOWN); + private static final ComponentDto UNKNOWN_COMPONENT = new ComponentDto().setUuid(UNKNOWN).setBranchUuid(UNKNOWN); private static final Set<String> QUALIFIERS_WITHOUT_LEAK_PERIOD = new HashSet<>(Arrays.asList(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.SUBVIEW)); private final DbClient dbClient; private final Clock clock; @@ -443,11 +443,11 @@ public class IssueQueryFactory { private static String toProjectUuid(ComponentDto componentDto) { String mainBranchProjectUuid = componentDto.getMainBranchProjectUuid(); - return mainBranchProjectUuid == null ? componentDto.projectUuid() : mainBranchProjectUuid; + return mainBranchProjectUuid == null ? componentDto.branchUuid() : mainBranchProjectUuid; } private static void setBranch(IssueQuery.Builder builder, ComponentDto component, @Nullable String branch, @Nullable String pullRequest) { - builder.branchUuid(branch == null && pullRequest == null ? null : component.projectUuid()); + builder.branchUuid(branch == null && pullRequest == null ? null : component.branchUuid()); builder.mainBranch(UNKNOWN_COMPONENT.equals(component) || (branch == null && pullRequest == null) || (branch != null && !branch.equals(component.getBranch())) diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureFavoriteTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureFavoriteTest.java index 7b9a964a8ee..cff63f8fc1a 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureFavoriteTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureFavoriteTest.java @@ -46,14 +46,14 @@ public class ComponentIndexFeatureFavoriteTest extends ComponentIndexTest { SuggestionQuery query1 = SuggestionQuery.builder() .setQuery("SonarQube") .setQualifiers(singletonList(PROJECT)) - .setFavoriteKeys(of(project1.getDbKey())) + .setFavoriteKeys(of(project1.getKey())) .build(); assertSearch(query1).containsExactly(uuids(project1, project2)); SuggestionQuery query2 = SuggestionQuery.builder() .setQuery("SonarQube") .setQualifiers(singletonList(PROJECT)) - .setFavoriteKeys(of(project2.getDbKey())) + .setFavoriteKeys(of(project2.getKey())) .build(); assertSearch(query2).containsExactly(uuids(project2, project1)); } @@ -66,7 +66,7 @@ public class ComponentIndexFeatureFavoriteTest extends ComponentIndexTest { SuggestionQuery query1 = SuggestionQuery.builder() .setQuery("bar") .setQualifiers(singletonList(PROJECT)) - .setFavoriteKeys(of(project1.getDbKey())) + .setFavoriteKeys(of(project1.getKey())) .build(); assertSearch(query1).isEmpty(); } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureRecentlyBrowsedTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureRecentlyBrowsedTest.java index d83901560b6..40567a496b2 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureRecentlyBrowsedTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureRecentlyBrowsedTest.java @@ -44,14 +44,14 @@ public class ComponentIndexFeatureRecentlyBrowsedTest extends ComponentIndexTest SuggestionQuery query1 = SuggestionQuery.builder() .setQuery("SonarQube") .setQualifiers(Collections.singletonList(PROJECT)) - .setRecentlyBrowsedKeys(of(project1.getDbKey())) + .setRecentlyBrowsedKeys(of(project1.getKey())) .build(); assertSearch(query1).containsExactly(uuids(project1, project2)); SuggestionQuery query2 = SuggestionQuery.builder() .setQuery("SonarQube") .setQualifiers(Collections.singletonList(PROJECT)) - .setRecentlyBrowsedKeys(of(project2.getDbKey())) + .setRecentlyBrowsedKeys(of(project2.getKey())) .build(); assertSearch(query2).containsExactly(uuids(project2, project1)); } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java index 3fbf4f34622..145a4eab0c4 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java @@ -122,15 +122,15 @@ public class ComponentIndexScoreTest extends ComponentIndexTest { assertSearch(SuggestionQuery.builder() .setQuery("File") .setQualifiers(asList(PROJECT, MODULE, FILE)) - .setRecentlyBrowsedKeys(ImmutableSet.of(file1.getDbKey())) - .setFavoriteKeys(ImmutableSet.of(file2.getDbKey())) + .setRecentlyBrowsedKeys(ImmutableSet.of(file1.getKey())) + .setFavoriteKeys(ImmutableSet.of(file2.getKey())) .build()).containsExactly(uuids(file2, file1)); assertSearch(SuggestionQuery.builder() .setQuery("File") .setQualifiers(asList(PROJECT, MODULE, FILE)) - .setRecentlyBrowsedKeys(ImmutableSet.of(file2.getDbKey())) - .setFavoriteKeys(ImmutableSet.of(file1.getDbKey())) + .setRecentlyBrowsedKeys(ImmutableSet.of(file2.getKey())) + .setFavoriteKeys(ImmutableSet.of(file1.getKey())) .build()).containsExactly(uuids(file1, file2)); } @@ -161,12 +161,12 @@ public class ComponentIndexScoreTest extends ComponentIndexTest { index(ComponentTesting.newFileDto(project) .setName("DbTester.java") - .setDbKey("java/org/example/DbTester.java") + .setKey("java/org/example/DbTester.java") .setUuid("UUID-DbTester")); index(ComponentTesting.newFileDto(project) .setName("WebhookDbTesting.java") - .setDbKey("java/org/example/WebhookDbTesting.java") + .setKey("java/org/example/WebhookDbTesting.java") .setUuid("UUID-WebhookDbTesting")); assertSearch("dbt").containsExactly( diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java index 9d15fe3a156..97ff35bad87 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java @@ -67,9 +67,9 @@ public class ComponentIndexSearchTest { @Test public void filter_by_key_with_exact_match() { - ComponentDto ignoredProject = db.components().insertPrivateProject(p -> p.setDbKey("ignored-project")); - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("shiny-project")); - db.components().insertPrivateProject(p -> p.setDbKey("another-shiny-project")); + ComponentDto ignoredProject = db.components().insertPrivateProject(p -> p.setKey("ignored-project")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("shiny-project")); + db.components().insertPrivateProject(p -> p.setKey("another-shiny-project")); index(ignoredProject, project); SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setQuery("shiny-project").build(), new SearchOptions()); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchWindowExceededTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchWindowExceededTest.java index a1fac9fd574..15681c4da4b 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchWindowExceededTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchWindowExceededTest.java @@ -65,7 +65,7 @@ public class ComponentIndexSearchWindowExceededTest { .setId(componentDoc.uuid()) .setKey(componentDoc.getKey()) .setName(componentDoc.name()) - .setProjectUuid(componentDoc.projectUuid()) + .setProjectUuid(componentDoc.branchUuid()) .setQualifier(componentDoc.qualifier()); } } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java index c9ab8e5a55c..06d683bd1b5 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java @@ -114,13 +114,13 @@ public abstract class ComponentIndexTest { protected ComponentDto indexProject(String key, String name) { return index( ComponentTesting.newPrivateProjectDto("UUID_" + key) - .setDbKey(key) + .setKey(key) .setName(name)); } protected ComponentDto newProject(String key, String name) { return ComponentTesting.newPrivateProjectDto("UUID_" + key) - .setDbKey(key) + .setKey(key) .setName(name); } @@ -132,7 +132,7 @@ public abstract class ComponentIndexTest { protected ComponentDto indexFile(ComponentDto project, String fileKey, String fileName) { return index( ComponentTesting.newFileDto(project) - .setDbKey(fileKey) + .setKey(fileKey) .setName(fileName)); } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java index 9ec67e24fb9..0a2f76b18c5 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java @@ -330,14 +330,14 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon { @Test public void filter_by_application_branch_having_project_branches() { - ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setDbKey("app")); + ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app")); ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1")); ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2")); - ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("prj1")); + ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1")); ComponentDto project1Branch1 = db.components().insertProjectBranch(project1); ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1)); ComponentDto project1Branch2 = db.components().insertProjectBranch(project1); - ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("prj2")); + ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2")); indexView(applicationBranch1.uuid(), asList(project1Branch1.uuid(), project2.uuid())); indexView(applicationBranch2.uuid(), singletonList(project1Branch2.uuid())); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java index 1bbc1bcc053..aa60a57c2b9 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java @@ -262,7 +262,7 @@ public class IssueIndexSyncProgressCheckerTest { ComponentDto subview = db.components().insertSubView(view); DbSession session = db.getSession(); - List<String> appViewOrSubviewKeys = Arrays.asList(projectDto1.getKey(), app.getDbKey(), view.getDbKey(), subview.getDbKey()); + List<String> appViewOrSubviewKeys = Arrays.asList(projectDto1.getKey(), app.getKey(), view.getKey(), subview.getKey()); // throws if flag set to TRUE assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java index e62a4b63528..4d26ed316be 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java @@ -218,7 +218,7 @@ public class IssueIndexTest extends IssueIndexTestCommon { userSessionRule.logIn(user1); assertThatSearchReturnsOnly(IssueQuery.builder(), "I1"); - assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(singletonList(project3.getDbKey()))); + assertThatSearchReturnsEmpty(IssueQuery.builder().projectUuids(singletonList(project3.getKey()))); userSessionRule.logIn(user2); assertThatSearchReturnsOnly(IssueQuery.builder(), "I2"); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java index 772d49480d1..3bb7a74ca8a 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java @@ -92,7 +92,7 @@ public class IssueQueryFactoryTest { .setStatuses(asList("CLOSED")) .setResolutions(asList("FALSE-POSITIVE")) .setResolved(true) - .setProjects(asList(project.getDbKey())) + .setProjects(asList(project.getKey())) .setDirectories(asList("aDirPath")) .setFiles(asList(file.uuid())) .setAssigneesUuid(asList(user.getUuid())) @@ -479,7 +479,7 @@ public class IssueQueryFactoryTest { public void onComponentOnly_restricts_search_to_specified_componentKeys() { ComponentDto project = db.components().insertPrivateProject(); SearchRequest request = new SearchRequest() - .setComponents(asList(project.getDbKey())) + .setComponents(asList(project.getKey())) .setOnComponentOnly(true); IssueQuery query = underTest.create(request); @@ -633,14 +633,14 @@ public class IssueQueryFactoryTest { @Test public void search_by_application_key_and_branch() { - ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setDbKey("app")); + ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app")); ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1")); ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2")); - ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("prj1")); + ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1")); ComponentDto project1Branch1 = db.components().insertProjectBranch(project1); ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1)); ComponentDto project1Branch2 = db.components().insertProjectBranch(project1); - ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("prj2")); + ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2")); db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1)); db.components().insertComponents(newProjectCopy(project2, applicationBranch1)); db.components().insertComponents(newProjectCopy(project1Branch2, applicationBranch2)); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java index 29c231ab8a3..cc5497e54ab 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java @@ -93,12 +93,12 @@ public class ProjectMeasuresIndexTest { private static final String NEW_LINES = "new_lines"; private static final String LANGUAGES = "languages"; - private static final ComponentDto PROJECT1 = ComponentTesting.newPrivateProjectDto().setUuid("Project-1").setName("Project 1").setDbKey("key-1"); - private static final ComponentDto PROJECT2 = ComponentTesting.newPrivateProjectDto().setUuid("Project-2").setName("Project 2").setDbKey("key-2"); - private static final ComponentDto PROJECT3 = ComponentTesting.newPrivateProjectDto().setUuid("Project-3").setName("Project 3").setDbKey("key-3"); - private static final ComponentDto APP1 = ComponentTesting.newApplication().setUuid("App-1").setName("App 1").setDbKey("app-key-1"); - private static final ComponentDto APP2 = ComponentTesting.newApplication().setUuid("App-2").setName("App 2").setDbKey("app-key-2"); - private static final ComponentDto APP3 = ComponentTesting.newApplication().setUuid("App-3").setName("App 3").setDbKey("app-key-3"); + private static final ComponentDto PROJECT1 = ComponentTesting.newPrivateProjectDto().setUuid("Project-1").setName("Project 1").setKey("key-1"); + private static final ComponentDto PROJECT2 = ComponentTesting.newPrivateProjectDto().setUuid("Project-2").setName("Project 2").setKey("key-2"); + private static final ComponentDto PROJECT3 = ComponentTesting.newPrivateProjectDto().setUuid("Project-3").setName("Project 3").setKey("key-3"); + private static final ComponentDto APP1 = ComponentTesting.newApplication().setUuid("App-1").setName("App 1").setKey("app-key-1"); + private static final ComponentDto APP2 = ComponentTesting.newApplication().setUuid("App-2").setName("App 2").setKey("app-key-2"); + private static final ComponentDto APP3 = ComponentTesting.newApplication().setUuid("App-3").setName("App 3").setKey("app-key-3"); private static final UserDto USER1 = newUserDto(); private static final UserDto USER2 = newUserDto(); private static final GroupDto GROUP1 = newGroupDto(); @@ -126,10 +126,10 @@ public class ProjectMeasuresIndexTest { @Test public void default_sort_is_by_ascending_case_insensitive_name_then_by_key() { - ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setDbKey("project1"); - ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setDbKey("project2"); - ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setDbKey("project3"); - ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setDbKey("project4"); + ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setKey("project1"); + ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setKey("project2"); + ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setKey("project3"); + ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setKey("project4"); index(newDoc(windows), newDoc(apachee), newDoc(apache1), newDoc(apache2)); assertResults(new ProjectMeasuresQuery(), apache1, apache2, apachee, windows); @@ -159,10 +159,10 @@ public class ProjectMeasuresIndexTest { @Test public void sort_by_a_metric_then_by_name_then_by_key() { - ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setDbKey("project1"); - ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setDbKey("project2"); - ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setDbKey("project3"); - ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setDbKey("project4"); + ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setKey("project1"); + ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setKey("project2"); + ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setKey("project3"); + ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setKey("project4"); index( newDoc(windows, NCLOC, 10_000d), newDoc(apachee, NCLOC, 5_000d), @@ -175,7 +175,7 @@ public class ProjectMeasuresIndexTest { @Test public void sort_by_quality_gate_status() { - ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setDbKey("key-4"); + ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setKey("key-4"); index( newDoc(PROJECT1).setQualityGateStatus(OK.name()), newDoc(PROJECT2).setQualityGateStatus(ERROR.name()), @@ -187,10 +187,10 @@ public class ProjectMeasuresIndexTest { @Test public void sort_by_quality_gate_status_then_by_name_then_by_key() { - ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setDbKey("project1"); - ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setDbKey("project2"); - ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setDbKey("project3"); - ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setDbKey("project4"); + ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setKey("project1"); + ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setKey("project2"); + ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setKey("project3"); + ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setKey("project4"); index( newDoc(windows).setQualityGateStatus(ERROR.name()), newDoc(apachee).setQualityGateStatus(OK.name()), @@ -422,7 +422,7 @@ public class ProjectMeasuresIndexTest { @Test public void filter_on_languages() { - ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setDbKey("key-4"); + ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setKey("key-4"); index( newDoc(PROJECT1).setLanguages(singletonList("java")), newDoc(PROJECT2).setLanguages(singletonList("xoo")), @@ -436,10 +436,10 @@ public class ProjectMeasuresIndexTest { @Test public void filter_on_query_text() { - ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setDbKey("project1"); - ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setDbKey("project2"); - ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setDbKey("project3"); - ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setDbKey("project4"); + ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setKey("project1"); + ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setKey("project2"); + ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setKey("project3"); + ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setKey("project4"); index(newDoc(windows), newDoc(apachee), newDoc(apache1), newDoc(apache2)); assertResults(new ProjectMeasuresQuery().setQueryText("windows"), windows); @@ -1736,7 +1736,7 @@ public class ProjectMeasuresIndexTest { private static ProjectMeasuresDoc newDoc(ComponentDto project) { return new ProjectMeasuresDoc() .setId(project.uuid()) - .setKey(project.getDbKey()) + .setKey(project.getKey()) .setName(project.name()) .setQualifier(project.qualifier()); } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java index 56d1732dec6..b8885dcf6d1 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java @@ -63,8 +63,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void search_partial_text_from_project_key() { index( - newDoc(newPrivateProjectDto().setUuid("struts").setName("Apache Struts").setDbKey("org.apache.commons.structs")), - newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setDbKey("org.sonar.sonarqube"))); + newDoc(newPrivateProjectDto().setUuid("struts").setName("Apache Struts").setKey("org.apache.commons.structs")), + newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setKey("org.sonar.sonarqube"))); assertTextQueryResults("apache", "struts"); assertTextQueryResults("apache.comm", "struts"); @@ -196,8 +196,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_exact_case_insensitive_key() { index( - newDoc(newPrivateProjectDto().setUuid("project1").setName("Windows").setDbKey("project1")), - newDoc(newPrivateProjectDto().setUuid("project2").setName("apachee").setDbKey("project2"))); + newDoc(newPrivateProjectDto().setUuid("project1").setName("Windows").setKey("project1")), + newDoc(newPrivateProjectDto().setUuid("project2").setName("apachee").setKey("project2"))); assertTextQueryResults("project1", "project1"); assertTextQueryResults("PROJECT1", "project1"); @@ -207,8 +207,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_key_with_dot() { index( - newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setDbKey("org.sonarqube")), - newDoc(newPrivateProjectDto().setUuid("sq").setName("SQ").setDbKey("sonarqube"))); + newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setKey("org.sonarqube")), + newDoc(newPrivateProjectDto().setUuid("sq").setName("SQ").setKey("sonarqube"))); assertTextQueryResults("org.sonarqube", "sonarqube"); assertNoResults("orgsonarqube"); @@ -220,8 +220,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_key_with_dash() { index( - newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setDbKey("org-sonarqube")), - newDoc(newPrivateProjectDto().setUuid("sq").setName("SQ").setDbKey("sonarqube"))); + newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setKey("org-sonarqube")), + newDoc(newPrivateProjectDto().setUuid("sq").setName("SQ").setKey("sonarqube"))); assertTextQueryResults("org-sonarqube", "sonarqube"); assertNoResults("orgsonarqube"); @@ -233,8 +233,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_key_with_colon() { index( - newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setDbKey("org:sonarqube")), - newDoc(newPrivateProjectDto().setUuid("sq").setName("SQ").setDbKey("sonarqube"))); + newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setKey("org:sonarqube")), + newDoc(newPrivateProjectDto().setUuid("sq").setName("SQ").setKey("sonarqube"))); assertTextQueryResults("org:sonarqube", "sonarqube"); assertNoResults("orgsonarqube"); @@ -245,7 +245,7 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_key_having_all_special_characters() { - index(newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setDbKey("org.sonarqube:sonar-sérvèr_ç"))); + index(newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setKey("org.sonarqube:sonar-sérvèr_ç"))); assertTextQueryResults("org.sonarqube:sonar-sérvèr_ç", "sonarqube"); } @@ -254,12 +254,12 @@ public class ProjectMeasuresIndexTextSearchTest { public void facets_take_into_account_text_search() { index( // docs with ncloc<1K - newDoc(newPrivateProjectDto().setName("Windows").setDbKey("project1"), NCLOC, 0d), - newDoc(newPrivateProjectDto().setName("apachee").setDbKey("project2"), NCLOC, 999d), + newDoc(newPrivateProjectDto().setName("Windows").setKey("project1"), NCLOC, 0d), + newDoc(newPrivateProjectDto().setName("apachee").setKey("project2"), NCLOC, 999d), // docs with ncloc>=1K and ncloc<10K - newDoc(newPrivateProjectDto().setName("Apache").setDbKey("project3"), NCLOC, 1_000d), + newDoc(newPrivateProjectDto().setName("Apache").setKey("project3"), NCLOC, 1_000d), // docs with ncloc>=100K and ncloc<500K - newDoc(newPrivateProjectDto().setName("Apache Foundation").setDbKey("project4"), NCLOC, 100_000d)); + newDoc(newPrivateProjectDto().setName("Apache Foundation").setKey("project4"), NCLOC, 100_000d)); assertNclocFacet(new ProjectMeasuresQuery().setQueryText("apache"), 1L, 1L, 0L, 1L, 0L); assertNclocFacet(new ProjectMeasuresQuery().setQueryText("PAch"), 1L, 1L, 0L, 1L, 0L); @@ -271,10 +271,10 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void filter_by_metric_take_into_account_text_search() { index( - newDoc(newPrivateProjectDto().setUuid("project1").setName("Windows").setDbKey("project1"), NCLOC, 30_000d), - newDoc(newPrivateProjectDto().setUuid("project2").setName("apachee").setDbKey("project2"), NCLOC, 40_000d), - newDoc(newPrivateProjectDto().setUuid("project3").setName("Apache").setDbKey("project3"), NCLOC, 50_000d), - newDoc(newPrivateProjectDto().setUuid("project4").setName("Apache").setDbKey("project4"), NCLOC, 60_000d)); + newDoc(newPrivateProjectDto().setUuid("project1").setName("Windows").setKey("project1"), NCLOC, 30_000d), + newDoc(newPrivateProjectDto().setUuid("project2").setName("apachee").setKey("project2"), NCLOC, 40_000d), + newDoc(newPrivateProjectDto().setUuid("project3").setName("Apache").setKey("project3"), NCLOC, 50_000d), + newDoc(newPrivateProjectDto().setUuid("project4").setName("Apache").setKey("project4"), NCLOC, 60_000d)); assertResults(new ProjectMeasuresQuery().setQueryText("apache").addMetricCriterion(MetricCriterion.create(NCLOC, GT, 20_000d)), "project3", "project4", "project2"); assertResults(new ProjectMeasuresQuery().setQueryText("apache").addMetricCriterion(MetricCriterion.create(NCLOC, LT, 55_000d)), "project3", "project2"); @@ -291,7 +291,7 @@ public class ProjectMeasuresIndexTextSearchTest { private static ProjectMeasuresDoc newDoc(ComponentDto project) { return new ProjectMeasuresDoc() .setId(project.uuid()) - .setKey(project.getDbKey()) + .setKey(project.getKey()) .setName(project.name()) .setQualifier(project.qualifier()); } diff --git a/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ce/RecentTasksDurationTaskTest.java b/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ce/RecentTasksDurationTaskTest.java index 5530f3e8a33..bfcee9972ad 100644 --- a/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ce/RecentTasksDurationTaskTest.java +++ b/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ce/RecentTasksDurationTaskTest.java @@ -54,7 +54,7 @@ public class RecentTasksDurationTaskTest { when(dbClient.ceActivityDao()).thenReturn(ceActivityDao); when(dbClient.componentDao()).thenReturn(componentDao); ComponentDto componentDto = new ComponentDto(); - componentDto.setDbKey("key"); + componentDto.setKey("key"); } @Test @@ -116,7 +116,7 @@ public class RecentTasksDurationTaskTest { for(int i=0; i<5; i++) { ComponentDto component = new ComponentDto(); component.setUuid(i + ""); - component.setDbKey(i + ""); + component.setKey(i + ""); componentDtos.add(component); } return componentDtos; diff --git a/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImpl.java b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImpl.java index 2e0e7f9b223..b73efa13e76 100644 --- a/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImpl.java +++ b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImpl.java @@ -106,7 +106,7 @@ public class IssueChangeEventServiceImpl implements IssueChangeEventService { IssueChangedEvent event = getIssueChangedEvent(projectKey, issuesInProject, issueChanges); if (event != null) { - persistEvent(event, entry.getValue().projectUuid()); + persistEvent(event, entry.getValue().branchUuid()); } } } diff --git a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java index 4fd9b9626d2..e171ae1c4f0 100644 --- a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java +++ b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java @@ -143,13 +143,13 @@ public class IssueChangeEventServiceImplTest { Set<DefaultIssue> issues = Set.of(defaultIssue1, defaultIssue2, issue3.toDefaultIssue()); Map<String, ComponentDto> projectsByUuid = new HashMap<>(); - projectsByUuid.put(componentDto1.projectUuid(), componentDto1); - projectsByUuid.put(componentDto2.projectUuid(), componentDto2); - projectsByUuid.put(componentDto3.projectUuid(), componentDto3); + projectsByUuid.put(componentDto1.branchUuid(), componentDto1); + projectsByUuid.put(componentDto2.branchUuid(), componentDto2); + projectsByUuid.put(componentDto3.branchUuid(), componentDto3); Map<String, BranchDto> branchesByProjectUuid = new HashMap<>(); - branchesByProjectUuid.put(componentDto1.projectUuid(), branch1); - branchesByProjectUuid.put(componentDto2.projectUuid(), branch2); - branchesByProjectUuid.put(componentDto3.projectUuid(), branch3); + branchesByProjectUuid.put(componentDto1.branchUuid(), branch1); + branchesByProjectUuid.put(componentDto2.branchUuid(), branch2); + branchesByProjectUuid.put(componentDto3.branchUuid(), branch3); underTest.distributeIssueChangeEvent(issues, projectsByUuid, branchesByProjectUuid); @@ -203,9 +203,9 @@ public class IssueChangeEventServiceImplTest { Set<DefaultIssue> issues = Set.of(defaultIssue1); Map<String, ComponentDto> projectsByUuid = new HashMap<>(); - projectsByUuid.put(project.projectUuid(), project); + projectsByUuid.put(project.branchUuid(), project); Map<String, BranchDto> branchesByProjectUuid = new HashMap<>(); - branchesByProjectUuid.put(project.projectUuid(), branch1); + branchesByProjectUuid.put(project.branchUuid(), branch1); underTest.distributeIssueChangeEvent(issues, projectsByUuid, branchesByProjectUuid); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/ImportHelper.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/ImportHelper.java index 3d37158da91..e5f979e7ee1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/ImportHelper.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/ImportHelper.java @@ -66,7 +66,7 @@ public class ImportHelper { public static CreateWsResponse toCreateResponse(ComponentDto componentDto) { return newBuilder() .setProject(Project.newBuilder() - .setKey(componentDto.getDbKey()) + .setKey(componentDto.getKey()) .setName(componentDto.name()) .setQualifier(componentDto.qualifier()) .setVisibility(Visibility.getLabel(componentDto.isPrivate()))) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectAction.java index 138ecb89723..3e702a0d74c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectAction.java @@ -123,7 +123,7 @@ public class ImportGitLabProjectAction implements AlmIntegrationsWsAction { private void populateMRSetting(DbSession dbSession, Long gitlabProjectId, ComponentDto componentDto, AlmSettingDto almSettingDto) { dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, new ProjectAlmSettingDto() - .setProjectUuid(componentDto.projectUuid()) + .setProjectUuid(componentDto.branchUuid()) .setAlmSettingUuid(almSettingDto.getUuid()) .setAlmRepo(gitlabProjectId.toString()) .setAlmSlug(null) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/BranchSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/BranchSupport.java index af8e1b3e547..9a98d40e968 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/BranchSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/BranchSupport.java @@ -47,7 +47,7 @@ public class BranchSupport { ComponentKey createComponentKey(String projectKey, Map<String, String> characteristics) { if (characteristics.isEmpty()) { - return new ComponentKeyImpl(projectKey, projectKey); + return new ComponentKeyImpl(projectKey); } else { checkState(delegate != null, "Current edition does not support branch feature"); } @@ -55,8 +55,7 @@ public class BranchSupport { return delegate.createComponentKey(projectKey, characteristics); } - ComponentDto createBranchComponent(DbSession dbSession, ComponentKey componentKey, - ComponentDto mainComponentDto, BranchDto mainComponentBranchDto) { + ComponentDto createBranchComponent(DbSession dbSession, ComponentKey componentKey, ComponentDto mainComponentDto, BranchDto mainComponentBranchDto) { checkState(delegate != null, "Current edition does not support branch feature"); return delegate.createBranchComponent(dbSession, componentKey, mainComponentDto, mainComponentBranchDto); @@ -65,8 +64,6 @@ public class BranchSupport { public abstract static class ComponentKey { public abstract String getKey(); - public abstract String getDbKey(); - public abstract Optional<String> getBranchName(); public abstract Optional<String> getPullRequestKey(); @@ -74,20 +71,13 @@ public class BranchSupport { public final boolean isMainBranch() { return !getBranchName().isPresent() && !getPullRequestKey().isPresent(); } - - /** - * @return the {@link ComponentKey} of the main branch for this component. - */ - public abstract ComponentKey getMainBranchComponentKey(); } private static final class ComponentKeyImpl extends ComponentKey { private final String key; - private final String dbKey; - public ComponentKeyImpl(String key, String dbKey) { + public ComponentKeyImpl(String key) { this.key = key; - this.dbKey = dbKey; } @Override @@ -96,11 +86,6 @@ public class BranchSupport { } @Override - public String getDbKey() { - return dbKey; - } - - @Override public Optional<String> getBranchName() { return Optional.empty(); } @@ -111,11 +96,6 @@ public class BranchSupport { } @Override - public ComponentKey getMainBranchComponentKey() { - return this; - } - - @Override public boolean equals(Object o) { if (this == o) { return true; @@ -124,13 +104,12 @@ public class BranchSupport { return false; } ComponentKeyImpl that = (ComponentKeyImpl) o; - return Objects.equals(key, that.key) && - Objects.equals(dbKey, that.dbKey); + return Objects.equals(key, that.key); } @Override public int hashCode() { - return Objects.hash(key, dbKey); + return Objects.hash(key); } } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java index 8e43f7fd803..7e42450ec13 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java @@ -63,8 +63,7 @@ public class ReportSubmitter { private final ProjectDefaultVisibility projectDefaultVisibility; public ReportSubmitter(CeQueue queue, UserSession userSession, ComponentUpdater componentUpdater, - PermissionTemplateService permissionTemplateService, DbClient dbClient, BranchSupport branchSupport, - ProjectDefaultVisibility projectDefaultVisibility) { + PermissionTemplateService permissionTemplateService, DbClient dbClient, BranchSupport branchSupport, ProjectDefaultVisibility projectDefaultVisibility) { this.queue = queue; this.userSession = userSession; this.componentUpdater = componentUpdater; @@ -87,17 +86,17 @@ public class ReportSubmitter { mainBranchComponent = mainBranchComponentOpt.get(); validateProject(dbSession, mainBranchComponent, projectKey); } else { - mainBranchComponent = createProject(dbSession, componentKey.getMainBranchComponentKey(), projectName); + mainBranchComponent = createProject(dbSession, componentKey.getKey(), projectName); projectCreated = true; } - BranchDto mainBranch = dbClient.branchDao().selectByUuid(dbSession, mainBranchComponent.projectUuid()) + BranchDto mainBranch = dbClient.branchDao().selectByUuid(dbSession, mainBranchComponent.branchUuid()) .orElseThrow(() -> new IllegalStateException("Couldn't find the main branch of the project")); ComponentDto branchComponent; if (isMainBranch(componentKey, mainBranch)) { branchComponent = mainBranchComponent; } else { - branchComponent = dbClient.componentDao().selectByKey(dbSession, componentKey.getDbKey()) + branchComponent = dbClient.componentDao().selectByKey(dbSession, componentKey.getKey()) .orElseGet(() -> branchSupport.createBranchComponent(dbSession, componentKey, mainBranchComponent, mainBranch)); } @@ -137,9 +136,9 @@ public class ReportSubmitter { if (!Qualifiers.PROJECT.equals(component.qualifier()) || !Scopes.PROJECT.equals(component.scope())) { errors.add(format("Component '%s' is not a project", rawProjectKey)); } - if (!component.projectUuid().equals(component.uuid())) { + if (!component.branchUuid().equals(component.uuid())) { // Project key is already used as a module of another project - ComponentDto anotherBaseProject = dbClient.componentDao().selectOrFailByUuid(dbSession, component.projectUuid()); + ComponentDto anotherBaseProject = dbClient.componentDao().selectOrFailByUuid(dbSession, component.branchUuid()); errors.add(format("The project '%s' is already defined in SonarQube but as a module of project '%s'. " + "If you really want to stop directly analysing project '%s', please first delete it from SonarQube and then relaunch the analysis of project '%s'.", rawProjectKey, anotherBaseProject.getKey(), anotherBaseProject.getKey(), rawProjectKey)); @@ -149,20 +148,19 @@ public class ReportSubmitter { } } - private ComponentDto createProject(DbSession dbSession, BranchSupport.ComponentKey componentKey, @Nullable String projectName) { + private ComponentDto createProject(DbSession dbSession, String projectKey, @Nullable String projectName) { userSession.checkPermission(GlobalPermission.PROVISION_PROJECTS); String userUuid = userSession.getUuid(); String userName = userSession.getLogin(); - boolean wouldCurrentUserHaveScanPermission = permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate( - dbSession, userUuid, componentKey.getDbKey()); + boolean wouldCurrentUserHaveScanPermission = permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(dbSession, userUuid, projectKey); if (!wouldCurrentUserHaveScanPermission) { throw insufficientPrivilegesException(); } NewComponent newProject = newComponentBuilder() - .setKey(componentKey.getKey()) - .setName(defaultIfBlank(projectName, componentKey.getKey())) + .setKey(projectKey) + .setName(defaultIfBlank(projectName, projectKey)) .setQualifier(Qualifiers.PROJECT) .setPrivate(getDefaultVisibility(dbSession).isPrivate()) .build(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java index 5a26580fdbb..b3daf2cb87d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java @@ -108,8 +108,7 @@ public class ComponentFinder { return getBranchOrPullRequest(dbSession, project.getUuid(), project.getKey(), branchKey, pullRequestKey); } - public BranchDto getBranchOrPullRequest(DbSession dbSession, String projectUuid, String projectKey, - @Nullable String branchKey, @Nullable String pullRequestKey) { + public BranchDto getBranchOrPullRequest(DbSession dbSession, String projectUuid, String projectKey, @Nullable String branchKey, @Nullable String pullRequestKey) { if (branchKey != null) { return dbClient.branchDao().selectByBranchKey(dbSession, projectUuid, branchKey) .orElseThrow(() -> new NotFoundException(String.format("Branch '%s' in project '%s' not found", branchKey, projectKey))); @@ -171,7 +170,7 @@ public class ComponentFinder { checkRequest(component.scope().equals(Scopes.PROJECT) && rootQualifiers.contains(component.qualifier()), format( "Component '%s' (id: %s) must be a project%s.", - component.getDbKey(), component.uuid(), + component.getKey(), component.uuid(), rootQualifiers.contains(Qualifiers.VIEW) ? " or a view" : "")); return component; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java index 55c76cf9789..a03e6848c62 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java @@ -143,8 +143,8 @@ public class ComponentUpdater { .setRootUuid(uuid) .setModuleUuid(null) .setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + uuid + ComponentDto.UUID_PATH_SEPARATOR) - .setProjectUuid(uuid) - .setDbKey(newComponent.key()) + .setBranchUuid(uuid) + .setKey(newComponent.key()) .setName(newComponent.name()) .setDescription(newComponent.description()) .setLongName(newComponent.name()) @@ -184,7 +184,7 @@ public class ComponentUpdater { private static PortfolioDto toPortfolioDto(ComponentDto component, long now) { return new PortfolioDto() .setUuid(component.uuid()) - .setRootUuid(component.projectUuid()) + .setRootUuid(component.branchUuid()) .setKey(component.getKey()) .setName(component.name()) .setPrivate(component.isPrivate()) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java index 6e39d8c4221..dd3cc2629b0 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java @@ -70,7 +70,7 @@ public class ComponentViewerJsonWriter { json.prop("longName", component.longName()); json.prop("q", component.qualifier()); - ComponentDto project = dbClient.componentDao().selectOrFailByUuid(session, component.projectUuid()); + ComponentDto project = dbClient.componentDao().selectOrFailByUuid(session, component.branchUuid()); json.prop("project", project.getKey()); json.prop("projectName", project.longName()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java index 5b8cb0dfa53..5320cd1f0e4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java @@ -129,14 +129,14 @@ public class SearchAction implements ComponentsWsAction { private Map<String, String> searchProjectsKeysByUuids(DbSession dbSession, List<ComponentDto> components) { Set<String> projectUuidsToSearch = components.stream() - .map(ComponentDto::projectUuid) + .map(ComponentDto::branchUuid) .collect(toHashSet()); List<ComponentDto> projects = dbClient.componentDao() .selectByUuids(dbSession, projectUuidsToSearch) .stream() .filter(c -> !c.qualifier().equals(Qualifiers.MODULE)) .collect(Collectors.toList()); - return projects.stream().collect(toMap(ComponentDto::uuid, ComponentDto::getDbKey)); + return projects.stream().collect(toMap(ComponentDto::uuid, ComponentDto::getKey)); } private static ComponentQuery buildEsQuery(SearchRequest request) { @@ -155,7 +155,7 @@ public class SearchAction implements ComponentsWsAction { .build(); components.stream() - .map(dto -> dtoToComponent(dto, projectKeysByUuids.get(dto.projectUuid()))) + .map(dto -> dtoToComponent(dto, projectKeysByUuids.get(dto.branchUuid()))) .forEach(responseBuilder::addComponents); return responseBuilder.build(); @@ -163,7 +163,7 @@ public class SearchAction implements ComponentsWsAction { private static Components.Component dtoToComponent(ComponentDto dto, String projectKey) { Components.Component.Builder builder = Components.Component.newBuilder() - .setKey(dto.getDbKey()) + .setKey(dto.getKey()) .setProject(projectKey) .setName(dto.name()) .setQualifier(dto.qualifier()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java index 9e42366a4eb..86f340835e0 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java @@ -110,7 +110,7 @@ public class ShowAction implements ComponentsWsAction { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto component = loadComponent(dbSession, request); userSession.checkComponentPermission(UserRole.USER, component); - Optional<SnapshotDto> lastAnalysis = dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, component.projectUuid()); + Optional<SnapshotDto> lastAnalysis = dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, component.branchUuid()); List<ComponentDto> ancestors = dbClient.componentDao().selectAncestors(dbSession, component); return buildResponse(dbSession, component, ancestors, lastAnalysis.orElse(null)); } @@ -149,7 +149,7 @@ public class ShowAction implements ComponentsWsAction { .setNeedIssueSync(needIssueSync); } else { Optional<ProjectDto> parentProject = dbClient.projectDao().selectByUuid(dbSession, - ofNullable(component.getMainBranchProjectUuid()).orElse(component.projectUuid())); + ofNullable(component.getMainBranchProjectUuid()).orElse(component.branchUuid())); boolean needIssueSync = needIssueSync(dbSession, component, parentProject.orElse(null)); return componentDtoToWsComponent(component, parentProject.orElse(null), lastAnalysis) .setNeedIssueSync(needIssueSync); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java index 114c385eaed..400e85f2557 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java @@ -215,7 +215,7 @@ public class SuggestionsAction implements ComponentsWsAction { } List<ComponentDto> favorites = favoriteFinder.list(); - Set<String> favoriteKeys = favorites.stream().map(ComponentDto::getDbKey).collect(MoreCollectors.toSet(favorites.size())); + Set<String> favoriteKeys = favorites.stream().map(ComponentDto::getKey).collect(MoreCollectors.toSet(favorites.size())); SuggestionQuery.Builder queryBuilder = SuggestionQuery.builder() .setQuery(query) .setRecentlyBrowsedKeys(recentlyBrowsedKeys) @@ -283,7 +283,7 @@ public class SuggestionsAction implements ComponentsWsAction { private Map<String, ComponentDto> loadProjects(DbSession dbSession, Collection<ComponentDto> components) { Set<String> projectUuids = components.stream() .filter(c -> QUALIFIERS_FOR_WHICH_TO_RETURN_PROJECT.contains(c.qualifier())) - .map(ComponentDto::projectUuid) + .map(ComponentDto::branchUuid) .collect(MoreCollectors.toSet()); return dbClient.componentDao().selectByUuids(dbSession, projectUuids).stream() .collect(MoreCollectors.uniqueIndex(ComponentDto::uuid)); @@ -330,17 +330,17 @@ public class SuggestionsAction implements ComponentsWsAction { ComponentDto result = componentsByUuids.get(hit.getUuid()); if (result == null // SONAR-11419 this has happened in production while code does not really allow it. An inconsistency in DB may be the cause. - || (QUALIFIERS_FOR_WHICH_TO_RETURN_PROJECT.contains(result.qualifier()) && projectsByUuids.get(result.projectUuid()) == null)) { + || (QUALIFIERS_FOR_WHICH_TO_RETURN_PROJECT.contains(result.qualifier()) && projectsByUuids.get(result.branchUuid()) == null)) { return null; } Suggestion.Builder builder = Suggestion.newBuilder() - .setKey(result.getDbKey()) + .setKey(result.getKey()) .setName(result.name()) .setMatch(hit.getHighlightedText().orElse(HtmlEscapers.htmlEscaper().escape(result.name()))) - .setIsRecentlyBrowsed(recentlyBrowsedKeys.contains(result.getDbKey())) + .setIsRecentlyBrowsed(recentlyBrowsedKeys.contains(result.getKey())) .setIsFavorite(favoriteUuids.contains(result.uuid())); if (QUALIFIERS_FOR_WHICH_TO_RETURN_PROJECT.contains(result.qualifier())) { - builder.setProject(projectsByUuids.get(result.projectUuid()).getDbKey()); + builder.setProject(projectsByUuids.get(result.branchUuid()).getKey()); } return builder.build(); } @@ -348,7 +348,7 @@ public class SuggestionsAction implements ComponentsWsAction { private static List<Project> toProjects(Map<String, ComponentDto> projectsByUuids) { return projectsByUuids.values().stream() .map(p -> Project.newBuilder() - .setKey(p.getDbKey()) + .setKey(p.getKey()) .setName(p.longName()) .build()) .collect(Collectors.toList()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java index 5c37c378a1c..5fd5e5de2a1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java @@ -245,7 +245,7 @@ public class TreeAction implements ComponentsWsAction { wsComponent = projectOrAppToWsComponent(projectDto, null); } else { Optional<ProjectDto> parentProject = dbClient.projectDao().selectByUuid(dbSession, - ofNullable(component.getMainBranchProjectUuid()).orElse(component.projectUuid())); + ofNullable(component.getMainBranchProjectUuid()).orElse(component.branchUuid())); wsComponent = componentDtoToWsComponent(component, parentProject.orElse(null), null); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java index d9fd4e55a8d..ee557d8bcc4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java @@ -229,7 +229,7 @@ public class SearchEventsAction implements DevelopersWsAction { Map<String, Long> fromDatesByProjectKey = IntStream.range(0, projectKeys.size()).boxed() .collect(uniqueIndex(projectKeys::get, fromDates::get)); return authorizedProjects.stream() - .map(dto -> new UuidFromPair(dto.uuid(), fromDatesByProjectKey.get(dto.getDbKey()))) + .map(dto -> new UuidFromPair(dto.uuid(), fromDatesByProjectKey.get(dto.getKey()))) .collect(toList(authorizedProjects.size())); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/Duplication.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/Duplication.java index df8c327f220..ea309f789cc 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/Duplication.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/Duplication.java @@ -47,7 +47,7 @@ public class Duplication { } static Duplication newComponent(ComponentDto componentDto, Integer from, Integer size) { - return new Duplication(componentDto, componentDto.getDbKey(), from, size, false); + return new Duplication(componentDto, componentDto.getKey(), from, size, false); } String componentDbKey() { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java index ed9ec049961..01adf616c0b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java @@ -56,7 +56,7 @@ public class DuplicationsParser { return blocks; } - DuplicationComparator duplicationComparator = new DuplicationComparator(component.uuid(), component.projectUuid()); + DuplicationComparator duplicationComparator = new DuplicationComparator(component.uuid(), component.branchUuid()); try { SMInputFactory inputFactory = initStax(); @@ -123,7 +123,7 @@ public class DuplicationsParser { } private static String convertToKey(String dbKey) { - return new ComponentDto().setDbKey(dbKey).getKey(); + return new ComponentDto().setKey(dbKey).getKey(); } private static SMInputFactory initStax() { @@ -191,7 +191,7 @@ public class DuplicationsParser { } private boolean sameProject(@Nullable ComponentDto otherDto) { - return otherDto == null || StringUtils.equals(otherDto.projectUuid(), projectUuid); + return otherDto == null || StringUtils.equals(otherDto.branchUuid(), projectUuid); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/ShowResponseBuilder.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/ShowResponseBuilder.java index 46f698e65fb..899372371a5 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/ShowResponseBuilder.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/ShowResponseBuilder.java @@ -98,7 +98,7 @@ public class ShowResponseBuilder { ComponentDto file = ref.getDto(); if (file != null) { - ComponentDto project = getProject(file.projectUuid(), projectsByUuid, session); + ComponentDto project = getProject(file.branchUuid(), projectsByUuid, session); response.putFiles(ref.getId(), toWsFile(file, project, branch, pullRequest)); } else { response.putFiles(ref.getId(), toWsFile(ref.getComponentKey(), branch, pullRequest)); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/SearchAction.java index b67a34e0039..eb16083bb55 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/SearchAction.java @@ -127,7 +127,7 @@ public class SearchAction implements FavoritesWsAction { private static Favorite toWsFavorite(Favorite.Builder builder, ComponentDto componentDto) { builder .clear() - .setKey(componentDto.getDbKey()); + .setKey(componentDto.getKey()); ofNullable(componentDto.name()).ifPresent(builder::setName); ofNullable(componentDto.qualifier()).ifPresent(builder::setQualifier); return builder.build(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsResponseFormatter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsResponseFormatter.java index 2f2232868b8..5c3490d17d0 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsResponseFormatter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsResponseFormatter.java @@ -19,6 +19,7 @@ */ package org.sonar.server.hotspot.ws; +import javax.annotation.Nullable; import org.sonar.db.component.ComponentDto; import org.sonarqube.ws.Hotspots; @@ -30,15 +31,15 @@ public class HotspotWsResponseFormatter { // nothing to do here } - Hotspots.Component formatComponent(Hotspots.Component.Builder builder, ComponentDto component) { + Hotspots.Component formatComponent(Hotspots.Component.Builder builder, ComponentDto component, @Nullable String branch, @Nullable String pr) { builder .clear() .setKey(component.getKey()) .setQualifier(component.qualifier()) .setName(component.name()) .setLongName(component.longName()); - ofNullable(component.getBranch()).ifPresent(builder::setBranch); - ofNullable(component.getPullRequest()).ifPresent(builder::setPullRequest); + ofNullable(branch).ifPresent(builder::setBranch); + ofNullable(pr).ifPresent(builder::setPullRequest); ofNullable(component.path()).ifPresent(builder::setPath); return builder.build(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java index ac4146c2966..b913d82127b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java @@ -32,6 +32,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.search.SearchResponse; @@ -56,6 +57,7 @@ import org.sonar.db.issue.IssueDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.protobuf.DbIssues; import org.sonar.db.rule.RuleDto; +import org.sonar.server.component.ComponentFinder; import org.sonar.server.es.SearchOptions; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.issue.TextRangeResponseFormatter; @@ -131,9 +133,8 @@ public class SearchAction implements HotspotsWsAction { private final TextRangeResponseFormatter textRangeFormatter; private final System2 system2; - public SearchAction(DbClient dbClient, UserSession userSession, IssueIndex issueIndex, - IssueIndexSyncProgressChecker issueIndexSyncProgressChecker, HotspotWsResponseFormatter responseFormatter, - TextRangeResponseFormatter textRangeFormatter, System2 system2) { + public SearchAction(DbClient dbClient, UserSession userSession, IssueIndex issueIndex, IssueIndexSyncProgressChecker issueIndexSyncProgressChecker, + HotspotWsResponseFormatter responseFormatter, TextRangeResponseFormatter textRangeFormatter, System2 system2) { this.dbClient = dbClient; this.userSession = userSession; this.issueIndex = issueIndex; @@ -347,7 +348,7 @@ public class SearchAction implements HotspotsWsAction { List<IssueDto> hotspots = toIssueDtos(dbSession, issueKeys); Paging paging = forPageIndex(wsRequest.getPage()).withPageSize(wsRequest.getIndex()).andTotal((int) getTotalHits(result).value); - return new SearchResponseData(paging, hotspots); + return new SearchResponseData(paging, hotspots, wsRequest.getBranch().orElse(null), wsRequest.getPullRequest().orElse(null)); } private static TotalHits getTotalHits(SearchResponse response) { @@ -635,7 +636,7 @@ public class SearchAction implements HotspotsWsAction { Hotspots.Component.Builder builder = Hotspots.Component.newBuilder(); for (ComponentDto component : components) { - responseBuilder.addComponents(responseFormatter.formatComponent(builder, component)); + responseBuilder.addComponents(responseFormatter.formatComponent(builder, component, searchResponseData.getBranch(), searchResponseData.getPullRequest())); } } @@ -660,8 +661,7 @@ public class SearchAction implements HotspotsWsAction { private final Set<String> sonarsourceSecurity; private final Set<String> cwe; private final Set<String> files; - - + private WsRequest(int page, int index, @Nullable String projectKey, @Nullable String branch, @Nullable String pullRequest, Set<String> hotspotKeys, @Nullable String status, @Nullable String resolution, @Nullable Boolean inNewCodePeriod, @Nullable Boolean onlyMine, @@ -774,12 +774,26 @@ public class SearchAction implements HotspotsWsAction { private static final class SearchResponseData { private final Paging paging; private final List<IssueDto> orderedHotspots; + private final String branch; + private final String pullRequest; private final Map<String, ComponentDto> componentsByUuid = new HashMap<>(); private final Map<RuleKey, RuleDto> rulesByRuleKey = new HashMap<>(); - private SearchResponseData(Paging paging, List<IssueDto> orderedHotspots) { + private SearchResponseData(Paging paging, List<IssueDto> orderedHotspots, @Nullable String branch, @Nullable String pullRequest) { this.paging = paging; this.orderedHotspots = orderedHotspots; + this.branch = branch; + this.pullRequest = pullRequest; + } + + @CheckForNull + public String getBranch() { + return branch; + } + + @CheckForNull + public String getPullRequest() { + return pullRequest; } boolean isEmpty() { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java index 39d3a514d8c..7a55dcb9530 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java @@ -38,6 +38,8 @@ import org.sonar.api.web.UserRole; import org.sonar.core.util.Uuids; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.db.component.BranchDto; +import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.protobuf.DbIssues; @@ -169,8 +171,8 @@ public class ShowAction implements HotspotsWsAction { private void formatComponents(Components components, ShowWsResponse.Builder responseBuilder) { responseBuilder - .setProject(responseFormatter.formatComponent(Hotspots.Component.newBuilder(), components.getProject())) - .setComponent(responseFormatter.formatComponent(Hotspots.Component.newBuilder(), components.getComponent())); + .setProject(responseFormatter.formatComponent(Hotspots.Component.newBuilder(), components.getProject(), components.getBranch(), components.getPullRequest())) + .setComponent(responseFormatter.formatComponent(Hotspots.Component.newBuilder(), components.getComponent(), components.getBranch(), components.getPullRequest())); responseBuilder.setCanChangeStatus(hotspotWsSupport.canChangeStatus(components.getProject())); } @@ -292,6 +294,7 @@ public class ShowAction implements HotspotsWsAction { String componentUuid = hotspot.getComponentUuid(); ComponentDto project = hotspotWsSupport.loadAndCheckProject(dbSession, hotspot, UserRole.USER); + BranchDto branch = dbClient.branchDao().selectByUuid(dbSession, project.branchUuid()).orElseThrow(() -> new IllegalStateException("Can't find branch " + project.branchUuid())); checkArgument(componentUuid != null, "Hotspot '%s' has no component", hotspot.getKee()); boolean hotspotOnProject = Objects.equals(project.uuid(), componentUuid); @@ -299,16 +302,38 @@ public class ShowAction implements HotspotsWsAction { : dbClient.componentDao().selectByUuid(dbSession, componentUuid) .orElseThrow(() -> new NotFoundException(format("Component with uuid '%s' does not exist", componentUuid))); - return new Components(project, component); + return new Components(project, component, branch); } private static final class Components { private final ComponentDto project; private final ComponentDto component; + private final String branch; + private final String pullRequest; - private Components(ComponentDto project, ComponentDto component) { + private Components(ComponentDto project, ComponentDto component, BranchDto branch) { this.project = project; this.component = component; + if (branch.isMain()) { + this.branch = null; + this.pullRequest = null; + } else if (branch.getBranchType() == BranchType.BRANCH) { + this.branch = branch.getKey(); + this.pullRequest = null; + } else { + this.branch = null; + this.pullRequest = branch.getKey(); + } + } + + @CheckForNull + public String getBranch() { + return branch; + } + + @CheckForNull + public String getPullRequest() { + return pullRequest; } public ComponentDto getProject() { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java index aa4ac9909c6..3eab766fcd1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java @@ -153,9 +153,9 @@ public class SearchResponseLoader { private void loadProjects(Collector collector, DbSession dbSession, SearchResponseData result) { Collection<ComponentDto> loadedComponents = result.getComponents(); for (ComponentDto component : loadedComponents) { - collector.addProjectUuid(component.projectUuid()); + collector.addProjectUuid(component.branchUuid()); } - Set<String> loadedProjectUuids = loadedComponents.stream().filter(cpt -> cpt.uuid().equals(cpt.projectUuid())).map(ComponentDto::uuid).collect(MoreCollectors.toSet()); + Set<String> loadedProjectUuids = loadedComponents.stream().filter(cpt -> cpt.uuid().equals(cpt.branchUuid())).map(ComponentDto::uuid).collect(MoreCollectors.toSet()); Set<String> projectUuidsToLoad = copyOf(difference(collector.getProjectUuids(), loadedProjectUuids)); if (!projectUuidsToLoad.isEmpty()) { List<ComponentDto> projects = dbClient.componentDao().selectByUuids(dbSession, collector.getProjectUuids()); @@ -208,7 +208,7 @@ public class SearchResponseLoader { Map<String, ComponentDto> componentsByProjectUuid = result.getComponents() .stream() .filter(ComponentDto::isRootProject) - .collect(MoreCollectors.uniqueIndex(ComponentDto::projectUuid)); + .collect(MoreCollectors.uniqueIndex(ComponentDto::branchUuid)); for (IssueDto issueDto : result.getIssues()) { // so that IssueDto can be used. if (fields.contains(ACTIONS)) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java index 957cfbf0705..42f74247d77 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java @@ -80,7 +80,7 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer { } List<QGChangeEvent> result = new ArrayList<>(); - Map<String, List<ComponentDto>> componentsByProjectUuid = components.stream().collect(groupingBy(ComponentDto::projectUuid)); + Map<String, List<ComponentDto>> componentsByProjectUuid = components.stream().collect(groupingBy(ComponentDto::branchUuid)); for (List<ComponentDto> groupedComponents : componentsByProjectUuid.values()) { Optional<QGChangeEvent> qgChangeEvent = refreshComponentsOnSameProject(dbSession, groupedComponents); qgChangeEvent.ifPresent(result::add); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java index 58a85033757..35e910cfba7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java @@ -78,7 +78,7 @@ public class LiveMeasureTreeUpdaterImpl implements LiveMeasureTreeUpdater { try { formula.computeHierarchy(context); } catch (RuntimeException e) { - throw new IllegalStateException("Fail to compute " + formula.getMetric().getKey() + " on " + context.getComponent().getDbKey(), e); + throw new IllegalStateException("Fail to compute " + formula.getMetric().getKey() + " on " + context.getComponent().getKey(), e); } } } @@ -98,7 +98,7 @@ public class LiveMeasureTreeUpdaterImpl implements LiveMeasureTreeUpdater { try { formula.compute(context, issueCounter); } catch (RuntimeException e) { - throw new IllegalStateException("Fail to compute " + formula.getMetric().getKey() + " on " + context.getComponent().getDbKey(), e); + throw new IllegalStateException("Fail to compute " + formula.getMetric().getKey() + " on " + context.getComponent().getKey(), e); } } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java index 62d4e80649c..88ddbdbc186 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java @@ -122,7 +122,7 @@ class MeasureMatrix { if (cell == null) { LiveMeasureDto measure = new LiveMeasureDto() .setComponentUuid(component.uuid()) - .setProjectUuid(component.projectUuid()) + .setProjectUuid(component.branchUuid()) .setMetricUuid(metricsByKeys.get(metricKey).getUuid()); cell = new MeasureCell(measure); table.put(component.uuid(), metricKey, cell); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index 0aa9dff22a0..da046ad0211 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -138,7 +138,7 @@ public class ComponentAction implements MeasuresWsAction { String pullRequest = request.getPullRequest(); ComponentDto component = loadComponent(dbSession, request, branch, pullRequest); checkPermissions(component); - SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null); + SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.branchUuid()).orElse(null); boolean isPR = isPR(pullRequest); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java index af0c153024e..77ee6758c95 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java @@ -39,7 +39,7 @@ class ComponentDtoToWsComponent { ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyComponentUuid()); if (referenceComponent != null) { - wsComponent.setRefKey(referenceComponent.getDbKey()); + wsComponent.setRefKey(referenceComponent.getKey()); } Measures.Measure.Builder measureBuilder = Measures.Measure.newBuilder(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java index 50f26aca4bb..64f179e5350 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java @@ -405,7 +405,7 @@ public class ComponentTreeAction implements MeasuresWsAction { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto baseComponent = loadComponent(dbSession, wsRequest); checkPermissions(baseComponent); - Optional<SnapshotDto> baseSnapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, baseComponent.projectUuid()); + Optional<SnapshotDto> baseSnapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, baseComponent.branchUuid()); if (baseSnapshot.isEmpty()) { return ComponentTreeData.builder() .setBaseComponent(baseComponent) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java index 179a4eaea50..2bf7d5975ef 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java @@ -180,7 +180,7 @@ public class SearchAction implements MeasuresWsAction { private List<Measure> buildWsMeasures() { Map<String, ComponentDto> componentsByUuid = projects.stream().collect(toMap(ComponentDto::uuid, Function.identity())); - Map<String, String> componentNamesByKey = projects.stream().collect(toMap(ComponentDto::getDbKey, ComponentDto::name)); + Map<String, String> componentNamesByKey = projects.stream().collect(toMap(ComponentDto::getKey, ComponentDto::name)); Map<String, MetricDto> metricsByUuid = metrics.stream().collect(toMap(MetricDto::getUuid, identity())); Function<LiveMeasureDto, MetricDto> dbMeasureToDbMetric = dbMeasure -> metricsByUuid.get(dbMeasure.getMetricUuid()); @@ -191,7 +191,7 @@ public class SearchAction implements MeasuresWsAction { return measures.stream() .map(dbMeasure -> { updateMeasureBuilder(measureBuilder, dbMeasureToDbMetric.apply(dbMeasure), dbMeasure); - measureBuilder.setComponent(componentsByUuid.get(dbMeasure.getComponentUuid()).getDbKey()); + measureBuilder.setComponent(componentsByUuid.get(dbMeasure.getComponentUuid()).getKey()); Measure measure = measureBuilder.build(); measureBuilder.clear(); return measure; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java index aa3abaf9fd2..7a956ba2f4b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java @@ -191,7 +191,7 @@ public class SearchHistoryAction implements MeasuresWsAction { private List<SnapshotDto> searchAnalyses(DbSession dbSession, SearchHistoryRequest request, ComponentDto component) { SnapshotQuery dbQuery = new SnapshotQuery() - .setComponentUuid(component.projectUuid()) + .setComponentUuid(component.branchUuid()) .setStatus(STATUS_PROCESSED) .setSort(SORT_FIELD.BY_DATE, SORT_ORDER.ASC); ofNullable(request.getFrom()).ifPresent(from -> dbQuery.setCreatedAfter(parseStartingDateOrDateTime(from).getTime())); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java index c9b3d8a809c..51076d2ac6e 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java @@ -182,7 +182,7 @@ public class ListAction implements NotificationsWsAction { Map<String, ComponentDto> projectsByUuid) { ComponentDto project = projectsByUuid.get(componentUuid); notification - .setProject(project.getDbKey()) + .setProject(project.getKey()) .setProjectName(project.name()); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java index be02376bcf1..5be67203ebc 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java @@ -80,7 +80,7 @@ public class PermissionTemplateService { return true; } - ComponentDto dto = new ComponentDto().setDbKey(projectKey).setQualifier(Qualifiers.PROJECT); + ComponentDto dto = new ComponentDto().setKey(projectKey).setQualifier(Qualifiers.PROJECT); PermissionTemplateDto template = findTemplate(dbSession, dto); if (template == null) { return false; @@ -195,11 +195,11 @@ public class PermissionTemplateService { List<PermissionTemplateDto> matchingTemplates = new ArrayList<>(); for (PermissionTemplateDto permissionTemplateDto : allPermissionTemplates) { String keyPattern = permissionTemplateDto.getKeyPattern(); - if (StringUtils.isNotBlank(keyPattern) && component.getDbKey().matches(keyPattern)) { + if (StringUtils.isNotBlank(keyPattern) && component.getKey().matches(keyPattern)) { matchingTemplates.add(permissionTemplateDto); } } - checkAtMostOneMatchForComponentKey(component.getDbKey(), matchingTemplates); + checkAtMostOneMatchForComponentKey(component.getKey(), matchingTemplates); if (matchingTemplates.size() == 1) { return matchingTemplates.get(0); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/CreateAction.java index f61420ec984..8d22d286e81 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/CreateAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.project.ws; -import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.server.ws.Change; @@ -100,18 +99,9 @@ public class CreateAction implements ProjectsWsAction { @Override public void handle(Request request, Response response) throws Exception { CreateRequest createRequest = toCreateRequest(request); - validate(createRequest); writeProtobuf(doHandle(createRequest), request, response); } - private static void validate(CreateRequest createRequest) { - Set<String> forbiddenNamePhrases = Set.of(":BRANCH:", ":PULLREQUEST:"); - if (forbiddenNamePhrases.stream().anyMatch(createRequest.getProjectKey()::contains)) { - throw new IllegalArgumentException(String.format("Invalid project key. Project key must not contain following phrases [%s]", - String.join(", ", forbiddenNamePhrases))); - } - } - private CreateWsResponse doHandle(CreateRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { userSession.checkPermission(PROVISION_PROJECTS); @@ -119,11 +109,11 @@ public class CreateAction implements ProjectsWsAction { boolean changeToPrivate = visibility == null ? projectDefaultVisibility.get(dbSession).isPrivate() : "private".equals(visibility); ComponentDto componentDto = componentUpdater.create(dbSession, newComponentBuilder() - .setKey(request.getProjectKey()) - .setName(request.getName()) - .setPrivate(changeToPrivate) - .setQualifier(PROJECT) - .build(), + .setKey(request.getProjectKey()) + .setName(request.getName()) + .setPrivate(changeToPrivate) + .setQualifier(PROJECT) + .build(), userSession.isLoggedIn() ? userSession.getUuid() : null, userSession.isLoggedIn() ? userSession.getLogin() : null); return toCreateResponse(componentDto); @@ -141,7 +131,7 @@ public class CreateAction implements ProjectsWsAction { private static CreateWsResponse toCreateResponse(ComponentDto componentDto) { return CreateWsResponse.newBuilder() .setProject(CreateWsResponse.Project.newBuilder() - .setKey(componentDto.getDbKey()) + .setKey(componentDto.getKey()) .setName(componentDto.name()) .setQualifier(componentDto.qualifier()) .setVisibility(Visibility.getLabel(componentDto.isPrivate()))) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java index 075515131f1..7631fcdb3d9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java @@ -210,7 +210,7 @@ public class SearchAction implements ProjectsWsAction { private static Component dtoToProject(ComponentDto dto, @Nullable SnapshotDto snapshot, @Nullable Long lastAnalysisDate) { Component.Builder builder = Component.newBuilder() - .setKey(dto.getDbKey()) + .setKey(dto.getKey()) .setName(dto.name()) .setQualifier(dto.qualifier()) .setVisibility(dto.isPrivate() ? PRIVATE.getLabel() : PUBLIC.getLabel()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java index 2b6a9edd8cd..00272da7f01 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java @@ -132,7 +132,7 @@ public class SearchMyProjectsAction implements ProjectsWsAction { public Project apply(ComponentDto dto) { Project.Builder project = Project.newBuilder(); project - .setKey(dto.getDbKey()) + .setKey(dto.getKey()) .setName(dto.name()); data.lastSnapshot(dto.uuid()).ifPresent(s -> { project.setLastAnalysisDate(formatDateTime(s.getCreatedAt())); @@ -172,7 +172,7 @@ public class SearchMyProjectsAction implements ProjectsWsAction { SearchMyProjectsData.Builder data = builder(); ProjectsResult searchResult = searchProjects(dbSession, request); List<ComponentDto> projects = searchResult.projects; - List<String> projectUuids = Lists.transform(projects, ComponentDto::projectUuid); + List<String> projectUuids = Lists.transform(projects, ComponentDto::branchUuid); List<ProjectLinkDto> projectLinks = dbClient.projectLinkDao().selectByProjectUuids(dbSession, projectUuids); List<SnapshotDto> snapshots = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, projectUuids); List<LiveMeasureDto> qualityGates = dbClient.liveMeasureDao() diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java index 6ad6f2f9172..d341ef6a1e4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java @@ -121,7 +121,7 @@ public class IssueSnippetsAction implements SourcesWsAction { } Supplier<Optional<Long>> periodDateSupplier = () -> dbClient.snapshotDao() - .selectLastAnalysisByComponentUuid(dbSession, fileDto.projectUuid()) + .selectLastAnalysisByComponentUuid(dbSession, fileDto.branchUuid()) .map(SnapshotDto::getPeriodDate); Iterable<DbFileSources.Line> lineSources = lineSourcesOpt.get(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java index c15a9cfc4db..109205b4b7f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java @@ -139,14 +139,14 @@ public class LinesAction implements SourcesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto file = loadComponent(dbSession, request); Supplier<Optional<Long>> periodDateSupplier = () -> dbClient.snapshotDao() - .selectLastAnalysisByComponentUuid(dbSession, file.projectUuid()) + .selectLastAnalysisByComponentUuid(dbSession, file.branchUuid()) .map(SnapshotDto::getPeriodDate); userSession.checkComponentPermission(UserRole.CODEVIEWER, file); int from = request.mandatoryParamAsInt(PARAM_FROM); int to = MoreObjects.firstNonNull(request.paramAsInt(PARAM_TO), Integer.MAX_VALUE); - Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "No source found for file '%s'", file.getDbKey()); + Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "No source found for file '%s'", file.getKey()); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); linesJsonWriter.writeSource(lines, json, periodDateSupplier); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java index c3005e1c79b..d49d0cefbb8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java @@ -156,7 +156,7 @@ public class ComponentAction implements NavigationWsAction { !userSession.isSystemAdministrator()) { throw insufficientPrivilegesException(); } - Optional<SnapshotDto> analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, component.projectUuid()); + Optional<SnapshotDto> analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, component.branchUuid()); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); @@ -181,7 +181,7 @@ public class ComponentAction implements NavigationWsAction { private ComponentDto getRootProjectOrBranch(ComponentDto component, DbSession session) { if (!component.isRootProject()) { - return dbClient.componentDao().selectOrFailByUuid(session, component.projectUuid()); + return dbClient.componentDao().selectOrFailByUuid(session, component.branchUuid()); } else { return component; } @@ -245,7 +245,7 @@ public class ComponentAction implements NavigationWsAction { } private void writeProfiles(JsonWriter json, DbSession dbSession, ComponentDto component) { - Set<QualityProfile> qualityProfiles = dbClient.liveMeasureDao().selectMeasure(dbSession, component.projectUuid(), QUALITY_PROFILES_KEY) + Set<QualityProfile> qualityProfiles = dbClient.liveMeasureDao().selectMeasure(dbSession, component.branchUuid(), QUALITY_PROFILES_KEY) .map(LiveMeasureDto::getDataAsString) .map(data -> QPMeasureData.fromJson(data).getProfiles()) .orElse(emptySortedSet()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/ImportHelperTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/ImportHelperTest.java index 828be41dc10..c4bb879a694 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/ImportHelperTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/ImportHelperTest.java @@ -85,6 +85,6 @@ public class ImportHelperTest { assertThat(project).extracting(CreateWsResponse.Project::getKey, CreateWsResponse.Project::getName, CreateWsResponse.Project::getQualifier) - .containsExactly(componentDto.getDbKey(), componentDto.name(), componentDto.qualifier()); + .containsExactly(componentDto.getKey(), componentDto.name(), componentDto.qualifier()); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java index ca76ed7b740..246f703a7bf 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java @@ -243,7 +243,7 @@ public class ImportAzureProjectActionTest { dto.setUserUuid(user.getUuid()); }); GsonAzureRepo repo = getGsonAzureRepo(); - db.components().insertPublicProject(p -> p.setDbKey(GENERATED_PROJECT_KEY)); + db.components().insertPublicProject(p -> p.setKey(GENERATED_PROJECT_KEY)); when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getDecryptedPersonalAccessToken(encryption), "project-name", "repo-name")).thenReturn(repo); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java index 574859d8c9f..b771a3a7514 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java @@ -138,7 +138,7 @@ public class ImportBitbucketCloudRepoActionTest { dto.setUserUuid(user.getUuid()); }); Repository repo = getGsonBBCRepo(); - db.components().insertPublicProject(p -> p.setDbKey(GENERATED_PROJECT_KEY)); + db.components().insertPublicProject(p -> p.setKey(GENERATED_PROJECT_KEY)); when(bitbucketCloudRestClient.getRepo(any(), any(), any())).thenReturn(repo); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java index 40063d4020d..aa3c09debec 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java @@ -105,8 +105,8 @@ public class SearchBitbucketCloudReposActionTest { dto.setAlmSettingUuid(almSetting.getUuid()); dto.setUserUuid(user.getUuid()); }); - ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("B")); - ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("A")); + ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setKey("B")); + ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setKey("A")); db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project1, s -> s.setAlmRepo("repo-slug-2")); db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project2, s -> s.setAlmRepo("repo-slug-2")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java index 97aa3145370..4541a89c1d8 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java @@ -149,7 +149,7 @@ public class ImportBitbucketServerProjectActionTest { }); Project project = getGsonBBSProject(); Repository repo = getGsonBBSRepo(project); - db.components().insertPublicProject(p -> p.setDbKey(GENERATED_PROJECT_KEY)); + db.components().insertPublicProject(p -> p.setKey(GENERATED_PROJECT_KEY)); assertThatThrownBy(() -> { when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/SearchBitbucketServerReposActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/SearchBitbucketServerReposActionTest.java index 3717cfd7167..6869ee0e6ae 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/SearchBitbucketServerReposActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/SearchBitbucketServerReposActionTest.java @@ -161,8 +161,8 @@ public class SearchBitbucketServerReposActionTest { dto.setAlmSettingUuid(almSetting.getUuid()); dto.setUserUuid(user.getUuid()); }); - ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("B")); - ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("A")); + ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setKey("B")); + ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setKey("A")); db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project1, s -> s.setAlmRepo("projectKey2"), s -> s.setAlmSlug("repo-slug-2")); db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project2, s -> s.setAlmRepo("projectKey2"), s -> s.setAlmSlug("repo-slug-2")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionTest.java index df54db59f9c..080436c2f36 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionTest.java @@ -120,7 +120,7 @@ public class ImportGithubProjectActionTest { public void importProject_ifProjectWithSameNameAlreadyExists_importSucceed() { AlmSettingDto githubAlmSetting = setupAlm(); db.almPats().insert(p -> p.setAlmSettingUuid(githubAlmSetting.getUuid()).setUserUuid(userSession.getUuid())); - db.components().insertPublicProject(p -> p.setDbKey("Hello-World")); + db.components().insertPublicProject(p -> p.setKey("Hello-World")); GithubApplicationClient.Repository repository = new GithubApplicationClient.Repository(1L, "Hello-World", false, "Hello-World", "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World", "main"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ListGithubRepositoriesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ListGithubRepositoriesActionTest.java index 552b1fa798a..31b74ebcb66 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ListGithubRepositoriesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ListGithubRepositoriesActionTest.java @@ -114,10 +114,10 @@ public class ListGithubRepositoriesActionTest { "https://github-enterprise.sonarqube.com/api/v3/github/HelloWorld", "main")) .collect(Collectors.toList()))); - ProjectDto project = db.components().insertPrivateProjectDto(componentDto -> componentDto.setDbKey("github_HelloWorld")); + ProjectDto project = db.components().insertPrivateProjectDto(componentDto -> componentDto.setKey("github_HelloWorld")); db.almSettings().insertGitHubProjectAlmSetting(githubAlmSettings, project, projectAlmSettingDto -> projectAlmSettingDto.setAlmRepo("github/HelloWorld")); - ProjectDto project2 = db.components().insertPrivateProjectDto(componentDto -> componentDto.setDbKey("github_HelloWorld2")); + ProjectDto project2 = db.components().insertPrivateProjectDto(componentDto -> componentDto.setKey("github_HelloWorld2")); db.almSettings().insertGitHubProjectAlmSetting(githubAlmSettings, project2, projectAlmSettingDto -> projectAlmSettingDto.setAlmRepo("github/HelloWorld")); ListGithubRepositoriesWsResponse response = ws.newRequest() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectDataLoaderTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectDataLoaderTest.java index 59eb17c30ce..1826d43fd89 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectDataLoaderTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectDataLoaderTest.java @@ -180,10 +180,10 @@ public class ProjectDataLoaderTest { .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) - .setProjectUuid(uuid) + .setBranchUuid(uuid) .setScope(scope) .setModuleUuid(moduleUuid) - .setDbKey(key)); + .setKey(key)); dbSession.commit(); try { @@ -209,7 +209,7 @@ public class ProjectDataLoaderTest { return new FileSourceDto() .setUuid(Uuids.createFast()) .setFileUuid(file.uuid()) - .setProjectUuid(file.projectUuid()) + .setProjectUuid(file.branchUuid()) .setDataHash("0263047cd758c68c27683625f072f010") .setLineHashes(of("8d7b3d6b83c0a517eac07e1aac94b773")) .setCreatedAt(System.currentTimeMillis()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/DeleteActionTest.java index b96071a878e..ae64da13e3e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/DeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/DeleteActionTest.java @@ -106,7 +106,7 @@ public class DeleteActionTest { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); assertThatThrownBy(() -> tester.newRequest() - .setParam("project", project.getDbKey()) + .setParam("project", project.getKey()) .setParam("branch", "branch1") .execute()) .isInstanceOf(NotFoundException.class) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java index fbc38e45601..aecd1c82c95 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java @@ -96,7 +96,7 @@ public class ListActionTest { @Test public void test_example() { - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("sonarqube")); db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime())); db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR")); @@ -115,7 +115,7 @@ public class ListActionTest { userSession.logIn().addProjectPermission(USER, project); String json = ws.newRequest() - .setParam("project", project.getDbKey()) + .setParam("project", project.getKey()) .execute() .getInput(); @@ -125,7 +125,7 @@ public class ListActionTest { @Test public void test_with_SCAN_EXCUTION_permission() { - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("sonarqube")); db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime())); db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR")); @@ -143,7 +143,7 @@ public class ListActionTest { userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); String json = ws.newRequest() - .setParam("project", project.getDbKey()) + .setParam("project", project.getKey()) .execute() .getInput(); @@ -156,7 +156,7 @@ public class ListActionTest { userSession.logIn().addProjectPermission(USER, project); ListWsResponse response = ws.newRequest() - .setParam("project", project.getDbKey()) + .setParam("project", project.getKey()) .executeProtobuf(ListWsResponse.class); assertThat(response.getBranchesList()) @@ -188,7 +188,7 @@ public class ListActionTest { userSession.logIn().addProjectPermission(USER, project); ListWsResponse response = ws.newRequest() - .setParam("project", project.getDbKey()) + .setParam("project", project.getKey()) .executeProtobuf(ListWsResponse.class); assertThat(response.getBranchesList()) @@ -252,7 +252,7 @@ public class ListActionTest { userSession.logIn().addProjectPermission(USER, application); ListWsResponse response = ws.newRequest() - .setParam("project", application.getDbKey()) + .setParam("project", application.getKey()) .executeProtobuf(ListWsResponse.class); assertThat(response.getBranchesList()) @@ -270,10 +270,10 @@ public class ListActionTest { ComponentDto branch = db.components().insertProjectBranch(project); assertThatThrownBy(() -> ws.newRequest() - .setParam("project", branch.getDbKey()) + .setParam("project", branch.getKey()) .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Project '%s' not found", branch.getKey())); } @Test @@ -289,9 +289,9 @@ public class ListActionTest { ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); userSession.logIn().addProjectPermission(USER, project); - assertThatThrownBy(() -> ws.newRequest().setParam("project", file.getDbKey()).execute()) + assertThatThrownBy(() -> ws.newRequest().setParam("project", file.getKey()).execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining("Project '" + file.getDbKey() + "' not found"); + .hasMessageContaining("Project '" + file.getKey() + "' not found"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java index e637c84154d..5041764425e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java @@ -112,7 +112,7 @@ public class BranchReportSubmitterTest { mockSuccessfulPrepareSubmitCall(); InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8); - underTest.submit(project.getDbKey(), project.name(), emptyMap(), reportInput); + underTest.submit(project.getKey(), project.name(), emptyMap(), reportInput); verifyNoInteractions(branchSupportDelegate); } @@ -125,17 +125,17 @@ public class BranchReportSubmitterTest { userSession.logIn(user).addProjectPermission(SCAN_EXECUTION, project); Map<String, String> randomCharacteristics = randomNonEmptyMap(); BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(branch); - when(branchSupportDelegate.createComponentKey(project.getDbKey(), randomCharacteristics)) + when(branchSupportDelegate.createComponentKey(project.getKey(), randomCharacteristics)) .thenReturn(componentKey); InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8); String taskUuid = mockSuccessfulPrepareSubmitCall(); - underTest.submit(project.getDbKey(), project.name(), randomCharacteristics, reportInput); + underTest.submit(project.getKey(), project.name(), randomCharacteristics, reportInput); verifyNoInteractions(permissionTemplateService); verifyNoInteractions(favoriteUpdater); verify(branchSupport, times(0)).createBranchComponent(any(), any(), any(), any()); - verify(branchSupportDelegate).createComponentKey(project.getDbKey(), randomCharacteristics); + verify(branchSupportDelegate).createComponentKey(project.getKey(), randomCharacteristics); verify(branchSupportDelegate, times(0)).createBranchComponent(any(), any(), any(), any()); verifyNoMoreInteractions(branchSupportDelegate); verifyQueueSubmit(project, branch, user, randomCharacteristics, taskUuid); @@ -150,19 +150,19 @@ public class BranchReportSubmitterTest { Map<String, String> randomCharacteristics = randomNonEmptyMap(); ComponentDto createdBranch = createButDoNotInsertBranch(existingProject); BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch); - when(branchSupportDelegate.createComponentKey(existingProject.getDbKey(), randomCharacteristics)) + when(branchSupportDelegate.createComponentKey(existingProject.getKey(), randomCharacteristics)) .thenReturn(componentKey); when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch))) .thenReturn(createdBranch); InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8); String taskUuid = mockSuccessfulPrepareSubmitCall(); - underTest.submit(existingProject.getDbKey(), existingProject.name(), randomCharacteristics, reportInput); + underTest.submit(existingProject.getKey(), existingProject.name(), randomCharacteristics, reportInput); verifyNoInteractions(permissionTemplateService); verifyNoInteractions(favoriteUpdater); verify(branchSupport).createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch)); - verify(branchSupportDelegate).createComponentKey(existingProject.getDbKey(), randomCharacteristics); + verify(branchSupportDelegate).createComponentKey(existingProject.getKey(), randomCharacteristics); verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch)); verifyNoMoreInteractions(branchSupportDelegate); @@ -181,7 +181,7 @@ public class BranchReportSubmitterTest { Map<String, String> randomCharacteristics = randomNonEmptyMap(); ComponentDto createdBranch = createButDoNotInsertBranch(nonExistingProject); BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch); - when(branchSupportDelegate.createComponentKey(nonExistingProject.getDbKey(), randomCharacteristics)) + when(branchSupportDelegate.createComponentKey(nonExistingProject.getKey(), randomCharacteristics)) .thenReturn(componentKey); when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getUuid()), eq(user.getLogin()), any())) .thenAnswer((Answer<ComponentDto>) invocation -> db.components().insertPrivateProject(nonExistingProject)); @@ -192,11 +192,11 @@ public class BranchReportSubmitterTest { String taskUuid = mockSuccessfulPrepareSubmitCall(); InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8); - underTest.submit(nonExistingProject.getDbKey(), nonExistingProject.name(), randomCharacteristics, reportInput); + underTest.submit(nonExistingProject.getKey(), nonExistingProject.name(), randomCharacteristics, reportInput); BranchDto exitingProjectMainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), nonExistingProject.uuid()).get(); verify(branchSupport).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), eq(exitingProjectMainBranch)); - verify(branchSupportDelegate).createComponentKey(nonExistingProject.getDbKey(), randomCharacteristics); + verify(branchSupportDelegate).createComponentKey(nonExistingProject.getKey(), randomCharacteristics); verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), eq(exitingProjectMainBranch)); verifyNoMoreInteractions(branchSupportDelegate); @@ -215,7 +215,7 @@ public class BranchReportSubmitterTest { when(branchSupportDelegate.createComponentKey(any(), any())).thenThrow(expected); try { - underTest.submit(project.getDbKey(), project.name(), randomCharacteristics, reportInput); + underTest.submit(project.getKey(), project.name(), randomCharacteristics, reportInput); fail("exception should have been thrown"); } catch (Exception e) { assertThat(e).isSameAs(expected); @@ -230,7 +230,7 @@ public class BranchReportSubmitterTest { Map<String, String> randomCharacteristics = randomNonEmptyMap(); ComponentDto createdBranch = createButDoNotInsertBranch(nonExistingProject); BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch); - String nonExistingProjectDbKey = nonExistingProject.getDbKey(); + String nonExistingProjectDbKey = nonExistingProject.getKey(); when(branchSupportDelegate.createComponentKey(nonExistingProjectDbKey, randomCharacteristics)) .thenReturn(componentKey); when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), any())) @@ -245,7 +245,7 @@ public class BranchReportSubmitterTest { private static ComponentDto createButDoNotInsertBranch(ComponentDto project) { BranchType randomBranchType = BranchType.values()[new Random().nextInt(BranchType.values().length)]; - BranchDto branchDto = newBranchDto(project.projectUuid(), randomBranchType); + BranchDto branchDto = newBranchDto(project.branchUuid(), randomBranchType); return ComponentTesting.newBranchComponent(project, branchDto); } @@ -264,20 +264,14 @@ public class BranchReportSubmitterTest { } private static BranchSupport.ComponentKey createComponentKeyOfBranch(ComponentDto branch) { - BranchSupport.ComponentKey mainComponentKey = mockComponentKey(branch.getKey(), branch.getKey()); - when(mainComponentKey.getMainBranchComponentKey()).thenReturn(mainComponentKey); - - BranchSupport.ComponentKey componentKey = mockComponentKey(branch.getKey(), branch.getDbKey()); + BranchSupport.ComponentKey componentKey = mockComponentKey(branch.getKey()); when(componentKey.getBranchName()).thenReturn(Optional.of(branch).map(ComponentDto::name)); - when(componentKey.getMainBranchComponentKey()).thenReturn(mainComponentKey); - return componentKey; } - private static BranchSupport.ComponentKey mockComponentKey(String key, String dbKey) { + private static BranchSupport.ComponentKey mockComponentKey(String key) { BranchSupport.ComponentKey componentKey = mock(BranchSupport.ComponentKey.class); when(componentKey.getKey()).thenReturn(key); - when(componentKey.getDbKey()).thenReturn(dbKey); return componentKey; } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchSupportTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchSupportTest.java index 67b4cecdf88..61a55cab202 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchSupportTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchSupportTest.java @@ -57,8 +57,6 @@ public class BranchSupportTest { assertThat(componentKey) .isEqualTo(underTestWithBranch.createComponentKey(projectKey, NO_CHARACTERISTICS)); assertThat(componentKey.getKey()).isEqualTo(projectKey); - assertThat(componentKey.getDbKey()).isEqualTo(projectKey); - assertThat(componentKey.getMainBranchComponentKey()).isSameAs(componentKey); assertThat(componentKey.getBranchName()).isEmpty(); assertThat(componentKey.getPullRequestKey()).isEmpty(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java index 937a7072b80..6c87dca07a3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java @@ -138,7 +138,7 @@ public class ReportSubmitterTest { userSession.logIn(user).addProjectPermission(SCAN_EXECUTION, project); mockSuccessfulPrepareSubmitCall(); - underTest.submit(project.getDbKey(), project.name(), emptyMap(), IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8)); + underTest.submit(project.getKey(), project.name(), emptyMap(), IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8)); verifyReportIsPersisted(TASK_UUID); verifyNoInteractions(permissionTemplateService); @@ -237,7 +237,7 @@ public class ReportSubmitterTest { userSession.addPermission(SCAN); mockSuccessfulPrepareSubmitCall(); - underTest.submit(project.getDbKey(), project.name(), emptyMap(), IOUtils.toInputStream("{binary}")); + underTest.submit(project.getKey(), project.name(), emptyMap(), IOUtils.toInputStream("{binary}")); verify(queue).submit(any(CeTaskSubmit.class)); } @@ -248,7 +248,7 @@ public class ReportSubmitterTest { userSession.addProjectPermission(SCAN_EXECUTION, project); mockSuccessfulPrepareSubmitCall(); - underTest.submit(project.getDbKey(), project.name(), emptyMap(), IOUtils.toInputStream("{binary}")); + underTest.submit(project.getKey(), project.name(), emptyMap(), IOUtils.toInputStream("{binary}")); verify(queue).submit(any(CeTaskSubmit.class)); } @@ -259,7 +259,7 @@ public class ReportSubmitterTest { userSession.logIn().addProjectPermission(SCAN_EXECUTION, component); mockSuccessfulPrepareSubmitCall(); - String dbKey = component.getDbKey(); + String dbKey = component.getKey(); String name = component.name(); Map<String, String> emptyMap = emptyMap(); InputStream stream = IOUtils.toInputStream("{binary}", UTF_8); @@ -275,7 +275,7 @@ public class ReportSubmitterTest { userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); mockSuccessfulPrepareSubmitCall(); - String moduleDbKey = module.getDbKey(); + String moduleDbKey = module.getKey(); String name = module.name(); Map<String, String> emptyMap = emptyMap(); InputStream inputStream = IOUtils.toInputStream("{binary}", UTF_8); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java index 97e4bbb792b..2af87ecd1bc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java @@ -294,7 +294,7 @@ public class ActivityActionTest { insertActivity("T1", project1, SUCCESS); insertActivity("T2", project2, FAILED); - ActivityResponse activityResponse = call(ws.newRequest().setParam("component", project1.getDbKey())); + ActivityResponse activityResponse = call(ws.newRequest().setParam("component", project1.getKey())); assertThat(activityResponse.getTasksCount()).isOne(); assertThat(activityResponse.getTasks(0).getId()).isEqualTo("T1"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java index 57417501bc5..6c2afc4a455 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java @@ -91,10 +91,10 @@ public class ActivityStatusActionTest { public void status_for_a_project_as_project_admin() { String projectKey = "project-key"; String anotherProjectKey = "another-project-key"; - ComponentDto project = newPrivateProjectDto().setDbKey(projectKey); - ComponentDto anotherProject = newPrivateProjectDto().setDbKey(anotherProjectKey); + ComponentDto project = newPrivateProjectDto().setKey(projectKey); + ComponentDto anotherProject = newPrivateProjectDto().setKey(anotherProjectKey); db.components().insertComponent(project); - db.components().insertComponent(newPrivateProjectDto().setDbKey(anotherProjectKey)); + db.components().insertComponent(newPrivateProjectDto().setKey(anotherProjectKey)); userSession.logIn().addProjectPermission(UserRole.ADMIN, project); // pending tasks returned insertInQueue(CeQueueDto.Status.PENDING, project); @@ -119,7 +119,7 @@ public class ActivityStatusActionTest { @Test public void add_pending_time() { String projectKey = "project-key"; - ComponentDto project = newPrivateProjectDto().setDbKey(projectKey); + ComponentDto project = newPrivateProjectDto().setKey(projectKey); db.components().insertComponent(project); userSession.logIn().addProjectPermission(UserRole.ADMIN, project); @@ -160,7 +160,7 @@ public class ActivityStatusActionTest { userSession.logIn(); ComponentDto project = db.components().insertPrivateProject(); - String dbKey = project.getDbKey(); + String dbKey = project.getKey(); assertThatThrownBy(() -> callByComponentKey(dbKey)) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/AnalysisStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/AnalysisStatusActionTest.java index 1592cc4a705..8288322c1af 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/AnalysisStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/AnalysisStatusActionTest.java @@ -293,7 +293,7 @@ public class AnalysisStatusActionTest { @Test public void json_example() { - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("com.github.kevinsawicki:http-request-parent") + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("com.github.kevinsawicki:http-request-parent") .setName("HttpRequest")); SnapshotDto analysis = db.components().insertSnapshot(project); CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java index 187040078bf..057c44514bf 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java @@ -169,7 +169,7 @@ public class CancelActionTest { } private static ComponentDto nonExistentComponentDot() { - return new ComponentDto().setUuid("does_not_exist").setProjectUuid("unknown"); + return new ComponentDto().setUuid("does_not_exist").setBranchUuid("unknown"); } private void logInAsSystemAdministrator() { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java index 87dafeab838..a08844c3293 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java @@ -118,7 +118,7 @@ public class ComponentActionTest { insertActivity("T1", project, CeActivityDto.Status.SUCCESS, analysis); Ce.ComponentResponse response = ws.newRequest() - .setParam(PARAM_COMPONENT, project.getDbKey()) + .setParam(PARAM_COMPONENT, project.getKey()) .executeProtobuf(Ce.ComponentResponse.class); assertThat(response.hasCurrent()).isTrue(); Ce.Task current = response.getCurrent(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java index e5dcca0070b..13d79e5507e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java @@ -104,7 +104,7 @@ public class TaskActionTest { assertThat(taskResponse.getTask().getStatus()).isEqualTo(Ce.TaskStatus.PENDING); assertThat(taskResponse.getTask().getSubmitterLogin()).isEqualTo(user.getLogin()); assertThat(taskResponse.getTask().getComponentId()).isEqualTo(privateProject.uuid()); - assertThat(taskResponse.getTask().getComponentKey()).isEqualTo(privateProject.getDbKey()); + assertThat(taskResponse.getTask().getComponentKey()).isEqualTo(privateProject.getKey()); assertThat(taskResponse.getTask().getComponentName()).isEqualTo(privateProject.name()); assertThat(taskResponse.getTask().hasExecutionTimeMs()).isFalse(); assertThat(taskResponse.getTask().getWarningCount()).isZero(); @@ -149,7 +149,7 @@ public class TaskActionTest { assertThat(task.getId()).isEqualTo(SOME_TASK_UUID); assertThat(task.getStatus()).isEqualTo(Ce.TaskStatus.FAILED); assertThat(task.getComponentId()).isEqualTo(privateProject.uuid()); - assertThat(task.getComponentKey()).isEqualTo(privateProject.getDbKey()); + assertThat(task.getComponentKey()).isEqualTo(privateProject.getKey()); assertThat(task.getComponentName()).isEqualTo(privateProject.name()); assertThat(task.getAnalysisId()).isEqualTo(activityDto.getAnalysisUuid()); assertThat(task.getExecutionTimeMs()).isEqualTo(500L); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskFormatterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskFormatterTest.java index c2e6ec45391..e59f4b394bc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskFormatterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskFormatterTest.java @@ -86,7 +86,7 @@ public class TaskFormatterTest { @Test public void formatQueue_with_component_and_other_fields() { String uuid = "COMPONENT_UUID"; - db.components().insertPrivateProject((t) -> t.setUuid(uuid).setDbKey("COMPONENT_KEY").setName("Component Name")); + db.components().insertPrivateProject((t) -> t.setUuid(uuid).setKey("COMPONENT_KEY").setName("Component Name")); UserDto user = db.users().insertUser(); CeQueueDto dto = new CeQueueDto(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java index 7ed73540c0a..db813338c1e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java @@ -103,10 +103,10 @@ public class ComponentFinderTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto branch = db.components().insertProjectBranch(project); - String branchDbKey = branch.getDbKey(); + String branchDbKey = branch.getKey(); assertThatThrownBy(() -> underTest.getByUuidOrKey(dbSession, null, branchDbKey, ID_AND_KEY)) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } @Test @@ -133,7 +133,7 @@ public class ComponentFinderTest { @Test public void fail_when_component_key_is_removed() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto()); - db.components().insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false)); + db.components().insertComponent(newFileDto(project).setKey("file-key").setEnabled(false)); assertThatThrownBy(() -> underTest.getByKey(dbSession, "file-key")) .isInstanceOf(NotFoundException.class) @@ -145,7 +145,7 @@ public class ComponentFinderTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto branch = db.components().insertProjectBranch(project); - String branchDbKey = branch.getDbKey(); + String branchDbKey = branch.getKey(); assertThatThrownBy(() -> underTest.getByKey(dbSession, branchDbKey)) .isInstanceOf(NotFoundException.class) .hasMessage(format("Component key '%s' not found", branchDbKey)); @@ -162,11 +162,11 @@ public class ComponentFinderTest { @Test public void get_component_by_key() { - db.components().insertComponent(newPrivateProjectDto().setDbKey("project-key")); + db.components().insertComponent(newPrivateProjectDto().setKey("project-key")); ComponentDto component = underTest.getByUuidOrKey(dbSession, null, "project-key", ID_AND_KEY); - assertThat(component.getDbKey()).isEqualTo("project-key"); + assertThat(component.getKey()).isEqualTo("project-key"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java index 5c4d384f0f1..2011ad12c26 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java @@ -64,8 +64,8 @@ public class ComponentServiceUpdateKeyTest { @Test public void update_project_key() { ComponentDto project = insertSampleProject(); - ComponentDto file = componentDb.insertComponent(ComponentTesting.newFileDto(project, null).setDbKey("sample:root:src/File.xoo")); - ComponentDto inactiveFile = componentDb.insertComponent(ComponentTesting.newFileDto(project, null).setDbKey("sample:root:src/InactiveFile.xoo").setEnabled(false)); + ComponentDto file = componentDb.insertComponent(ComponentTesting.newFileDto(project, null).setKey("sample:root:src/File.xoo")); + ComponentDto inactiveFile = componentDb.insertComponent(ComponentTesting.newFileDto(project, null).setKey("sample:root:src/InactiveFile.xoo").setEnabled(false)); dbSession.commit(); @@ -74,15 +74,15 @@ public class ComponentServiceUpdateKeyTest { dbSession.commit(); // Check project key has been updated - assertThat(db.getDbClient().componentDao().selectByKey(dbSession, project.getDbKey())).isEmpty(); + assertThat(db.getDbClient().componentDao().selectByKey(dbSession, project.getKey())).isEmpty(); assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root")).isNotNull(); // Check file key has been updated - assertThat(db.getDbClient().componentDao().selectByKey(dbSession, file.getDbKey())).isEmpty(); + assertThat(db.getDbClient().componentDao().selectByKey(dbSession, file.getKey())).isEmpty(); assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root:src/File.xoo")).isNotNull(); assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root:src/InactiveFile.xoo")).isNotNull(); - assertThat(dbClient.componentDao().selectByKey(dbSession, inactiveFile.getDbKey())).isEmpty(); + assertThat(dbClient.componentDao().selectByKey(dbSession, inactiveFile.getKey())).isEmpty(); assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue(); @@ -108,7 +108,7 @@ public class ComponentServiceUpdateKeyTest { underTest.updateKey(dbSession, componentDb.getProjectDto(provisionedProject), "provisionedProject2"); dbSession.commit(); - assertComponentKeyHasBeenUpdated(provisionedProject.getDbKey(), "provisionedProject2"); + assertComponentKeyHasBeenUpdated(provisionedProject.getKey(), "provisionedProject2"); assertThat(projectIndexers.hasBeenCalled(provisionedProject.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue(); } @@ -129,7 +129,7 @@ public class ComponentServiceUpdateKeyTest { logInAsProjectAdministrator(project); ProjectDto projectDto = componentDb.getProjectDto(project); - String anotherProjectDbKey = anotherProject.getDbKey(); + String anotherProjectDbKey = anotherProject.getKey(); assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, anotherProjectDbKey)) .isInstanceOf(IllegalArgumentException.class) @@ -163,7 +163,7 @@ public class ComponentServiceUpdateKeyTest { } private ComponentDto insertProject(String key) { - return componentDb.insertPrivateProject(c -> c.setDbKey(key)); + return componentDb.insertPrivateProject(c -> c.setKey(key)); } private void assertComponentKeyHasBeenUpdated(String oldKey, String newKey) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java index 35b27f35e02..fee559a446e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java @@ -81,13 +81,13 @@ public class ComponentUpdaterTest { ComponentDto returned = underTest.create(db.getSession(), project, null, null); ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid()); - assertThat(loaded.getDbKey()).isEqualTo(DEFAULT_PROJECT_KEY); + assertThat(loaded.getKey()).isEqualTo(DEFAULT_PROJECT_KEY); assertThat(loaded.name()).isEqualTo(DEFAULT_PROJECT_NAME); assertThat(loaded.longName()).isEqualTo(DEFAULT_PROJECT_NAME); assertThat(loaded.qualifier()).isEqualTo(Qualifiers.PROJECT); assertThat(loaded.scope()).isEqualTo(Scopes.PROJECT); assertThat(loaded.uuid()).isNotNull(); - assertThat(loaded.projectUuid()).isEqualTo(loaded.uuid()); + assertThat(loaded.branchUuid()).isEqualTo(loaded.uuid()); assertThat(loaded.moduleUuid()).isNull(); assertThat(loaded.moduleUuidPath()).isEqualTo("." + loaded.uuid() + "."); assertThat(loaded.isPrivate()).isEqualTo(project.isPrivate()); @@ -140,7 +140,7 @@ public class ComponentUpdaterTest { ComponentDto returned = underTest.create(db.getSession(), view, null, null); ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid()); - assertThat(loaded.getDbKey()).isEqualTo("view-key"); + assertThat(loaded.getKey()).isEqualTo("view-key"); assertThat(loaded.name()).isEqualTo("view-name"); assertThat(loaded.qualifier()).isEqualTo("VW"); assertThat(projectIndexers.hasBeenCalled(loaded.uuid(), ProjectIndexer.Cause.PROJECT_CREATION)).isTrue(); @@ -159,7 +159,7 @@ public class ComponentUpdaterTest { ComponentDto returned = underTest.create(db.getSession(), application, null, null); ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid()); - assertThat(loaded.getDbKey()).isEqualTo("app-key"); + assertThat(loaded.getKey()).isEqualTo("app-key"); assertThat(loaded.name()).isEqualTo("app-name"); assertThat(loaded.qualifier()).isEqualTo("APP"); assertThat(projectIndexers.hasBeenCalled(loaded.uuid(), ProjectIndexer.Cause.PROJECT_CREATION)).isTrue(); @@ -248,12 +248,12 @@ public class ComponentUpdaterTest { DbSession session = db.getSession(); NewComponent newComponent = NewComponent.newComponentBuilder() - .setKey(existing.getDbKey()) + .setKey(existing.getKey()) .setName(DEFAULT_PROJECT_NAME) .build(); assertThatThrownBy(() -> underTest.create(session, newComponent, null, null)) .isInstanceOf(BadRequestException.class) - .hasMessage("Could not create Project with key: \"%s\". A similar key already exists: \"%s\"", existing.getDbKey(), existing.getDbKey()); + .hasMessage("Could not create Project, key already exists: " + existing.getKey()); } @Test @@ -283,7 +283,7 @@ public class ComponentUpdaterTest { @Test public void create_shouldFail_whenCreatingProjectWithExistingKeyButDifferentCase() { String existingKey = randomAlphabetic(5).toUpperCase(); - db.components().insertPrivateProject(component -> component.setDbKey(existingKey)); + db.components().insertPrivateProject(component -> component.setKey(existingKey)); String newKey = existingKey.toLowerCase(); NewComponent newComponent = NewComponent.newComponentBuilder() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/AppActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/AppActionTest.java index 7a5aa84dcc7..2b7e5c30c42 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/AppActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/AppActionTest.java @@ -174,7 +174,7 @@ public class AppActionTest { userSession.logIn("john").addProjectPermission(USER, project); String result = ws.newRequest() - .setParam("component", file.getDbKey()) + .setParam("component", file.getKey()) .execute() .getInput(); @@ -299,7 +299,7 @@ public class AppActionTest { ComponentDto file = db.components().insertComponent(newFileDto(branch)); String result = ws.newRequest() - .setParam("component", file.getDbKey()) + .setParam("component", file.getKey()) .setParam("branch", file.getBranch()) .execute() .getInput(); @@ -328,7 +328,7 @@ public class AppActionTest { ComponentDto file = db.components().insertComponent(newFileDto(branch)); String result = ws.newRequest() - .setParam("component", file.getDbKey()) + .setParam("component", file.getKey()) .setParam("pullRequest", file.getPullRequest()) .execute() .getInput(); @@ -357,7 +357,7 @@ public class AppActionTest { ComponentDto file = db.components().insertComponent(newFileDto(branch)); TestRequest request = ws.newRequest() - .setParam("component", file.getDbKey()) + .setParam("component", file.getKey()) .setParam("branch", "unknown_branch") .setParam("pullRequest", "unknown_component"); assertThatThrownBy(request::execute) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java index 3a3d074f793..771f7f0ac4a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java @@ -125,8 +125,8 @@ public class SearchActionTest { @Test public void search_by_key_query() { insertProjectsAuthorizedForUser( - ComponentTesting.newPrivateProjectDto().setDbKey("project-_%-key"), - ComponentTesting.newPrivateProjectDto().setDbKey("project-key-without-escaped-characters")); + ComponentTesting.newPrivateProjectDto().setKey("project-_%-key"), + ComponentTesting.newPrivateProjectDto().setKey("project-key-without-escaped-characters")); SearchWsResponse response = call(new SearchRequest().setQuery("project-_%-key").setQualifiers(singletonList(PROJECT))); @@ -137,7 +137,7 @@ public class SearchActionTest { public void search_with_pagination() { List<ComponentDto> componentDtoList = new ArrayList<>(); for (int i = 1; i <= 9; i++) { - componentDtoList.add(newPrivateProjectDto("project-uuid-" + i).setDbKey("project-key-" + i).setName("Project Name " + i)); + componentDtoList.add(newPrivateProjectDto("project-uuid-" + i).setKey("project-key-" + i).setName("Project Name " + i)); } insertProjectsAuthorizedForUser(componentDtoList.toArray(new ComponentDto[] {})); @@ -158,7 +158,7 @@ public class SearchActionTest { SearchWsResponse response = call(new SearchRequest().setQualifiers(singletonList(PROJECT))); assertThat(response.getComponentsList()).extracting(Component::getKey) - .containsExactlyInAnyOrder(project1.getDbKey()); + .containsExactlyInAnyOrder(project1.getKey()); assertThat(response.getPaging().getTotal()).isOne(); } @@ -166,16 +166,16 @@ public class SearchActionTest { public void return_project_key() { ComponentDto project = ComponentTesting.newPublicProjectDto(); ComponentDto module = ComponentTesting.newModuleDto(project); - ComponentDto dir1 = newDirectory(module, "dir1").setDbKey("dir1"); - ComponentDto dir2 = newDirectory(module, "dir2").setDbKey("dir2"); - ComponentDto dir3 = newDirectory(project, "dir3").setDbKey("dir3"); + ComponentDto dir1 = newDirectory(module, "dir1").setKey("dir1"); + ComponentDto dir2 = newDirectory(module, "dir2").setKey("dir2"); + ComponentDto dir3 = newDirectory(project, "dir3").setKey("dir3"); db.components().insertComponents(project, module, dir1, dir2, dir3); setBrowsePermissionOnUserAndIndex(project); SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT, APP))); assertThat(response.getComponentsList()).extracting(Component::getKey, Component::getProject) - .containsOnly(tuple(project.getDbKey(), project.getDbKey())); + .containsOnly(tuple(project.getKey(), project.getKey())); } @Test @@ -187,7 +187,7 @@ public class SearchActionTest { SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT))); assertThat(response.getComponentsList()).extracting(Component::getKey) - .containsOnly(project.getDbKey()); + .containsOnly(project.getKey()); } @Test @@ -209,9 +209,9 @@ public class SearchActionTest { @Test public void test_json_example() { db.components().insertComponent(newPortfolio()); - ComponentDto project = newPrivateProjectDto("project-uuid").setName("Project Name").setDbKey("project-key"); - ComponentDto module = newModuleDto("module-uuid", project).setName("Module Name").setDbKey("module-key"); - ComponentDto directory = newDirectory(module, "path/to/directoy").setUuid("directory-uuid").setDbKey("directory-key").setName("Directory Name"); + ComponentDto project = newPrivateProjectDto("project-uuid").setName("Project Name").setKey("project-key"); + ComponentDto module = newModuleDto("module-uuid", project).setName("Module Name").setKey("module-key"); + ComponentDto directory = newDirectory(module, "path/to/directoy").setUuid("directory-uuid").setKey("directory-key").setName("Directory Name"); ComponentDto view = newPortfolio(); db.components().insertComponents(project, module, directory, view); setBrowsePermissionOnUserAndIndex(project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index 83ba890ff27..03bbabbe88f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -236,17 +236,17 @@ public class SearchProjectsActionTest { userSession.logIn(); MetricDto coverage = db.measures().insertMetric(c -> c.setKey(COVERAGE).setValueType("PERCENT")); ComponentDto project1 = insertProject( - c -> c.setDbKey(KEY_PROJECT_EXAMPLE_001).setName("My Project 1"), + c -> c.setKey(KEY_PROJECT_EXAMPLE_001).setName("My Project 1"), p -> p.setTagsString("finance, java"), new Measure(coverage, c -> c.setValue(80d))); db.components().insertProjectBranch(db.components().getProjectDto(project1), branchDto -> branchDto.setNeedIssueSync(true)); ComponentDto project2 = insertProject( - c -> c.setDbKey(KEY_PROJECT_EXAMPLE_002).setName("My Project 2"), + c -> c.setKey(KEY_PROJECT_EXAMPLE_002).setName("My Project 2"), new Measure(coverage, c -> c.setValue(90d))); ComponentDto project3 = insertProject( - c -> c.setDbKey(KEY_PROJECT_EXAMPLE_003).setName("My Project 3"), + c -> c.setKey(KEY_PROJECT_EXAMPLE_003).setName("My Project 3"), p -> p.setTagsString("sales, offshore, java"), new Measure(coverage, c -> c.setValue(20d))); addFavourite(project1); @@ -265,7 +265,7 @@ public class SearchProjectsActionTest { .executeProtobuf(SearchProjectsWsResponse.class); assertThat(protobufResult.getComponentsList()).extracting(Component::getKey) - .containsExactly(project1.getDbKey(), project2.getDbKey(), project3.getDbKey()); + .containsExactly(project1.getKey(), project2.getKey(), project3.getKey()); } @Test @@ -330,7 +330,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("coverage <= 80 and ncloc <= 10000")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getKey()); } @Test @@ -346,7 +346,7 @@ public class SearchProjectsActionTest { assertThat(result.getComponentsList()) .extracting(Component::getKey) - .containsExactlyInAnyOrder(project1.getDbKey(), project2.getDbKey()); + .containsExactlyInAnyOrder(project1.getKey(), project2.getKey()); } @Test @@ -366,7 +366,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("languages IN (java, js, <null>)")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project2.getDbKey(), project4.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project2.getKey(), project4.getKey()); } @Test @@ -381,7 +381,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter(metricKey + " = 2")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getKey()); } @Test @@ -396,7 +396,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter(newMetricKey + " = 2")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getKey()); } @Test @@ -409,7 +409,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("tags in (finance, offshore)")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.getKey()); } @Test @@ -423,7 +423,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("coverage <= 80")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.getKey()); } @Test @@ -437,7 +437,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("new_coverage <= 80")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.getKey()); } @Test @@ -451,7 +451,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("duplicated_lines_density <= 80")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.getKey()); } @Test @@ -466,7 +466,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("duplicated_lines_density = NO_DATA")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey()); } @Test @@ -493,7 +493,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("new_duplicated_lines_density <= 80")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.getKey()); } @Test @@ -507,7 +507,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("ncloc <= 80")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.getKey()); } @Test @@ -521,16 +521,16 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("new_lines <= 80")); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.getKey()); } @Test public void filter_projects_by_text_query() { userSession.logIn(); - insertProject(c -> c.setDbKey("sonar-java").setName("Sonar Java")); - insertProject(c -> c.setDbKey("sonar-groovy").setName("Sonar Groovy")); - insertProject(c -> c.setDbKey("sonar-markdown").setName("Sonar Markdown")); - insertProject(c -> c.setDbKey("sonarqube").setName("Sonar Qube")); + insertProject(c -> c.setKey("sonar-java").setName("Sonar Java")); + insertProject(c -> c.setKey("sonar-groovy").setName("Sonar Groovy")); + insertProject(c -> c.setKey("sonar-markdown").setName("Sonar Markdown")); + insertProject(c -> c.setKey("sonarqube").setName("Sonar Qube")); index(); assertThat(call(request.setFilter("query = \"Groovy\"")).getComponentsList()).extracting(Component::getName).containsOnly("Sonar Groovy"); @@ -551,7 +551,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("isFavorite")); assertThat(result.getComponentsCount()).isEqualTo(2); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(javaProject.getDbKey(), markDownProject.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(javaProject.getKey(), markDownProject.getKey()); } @Test @@ -568,7 +568,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request.setFilter("isFavorite")); assertThat(result.getComponentsCount()).isEqualTo(2); - assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(javaProject.getDbKey(), markDownProject.getDbKey()); + assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(javaProject.getKey(), markDownProject.getKey()); } @Test @@ -613,7 +613,7 @@ public class SearchProjectsActionTest { .containsExactly( Stream.of(application1, application2, application3, project1, project2, project3) .filter(c -> Stream.of(qualifiers).anyMatch(s -> s.equals(c.qualifier()))) - .map(ComponentDto::getDbKey) + .map(ComponentDto::getKey) .toArray(String[]::new)); } @@ -639,7 +639,7 @@ public class SearchProjectsActionTest { assertThat(result.getComponentsCount()).isEqualTo(3); assertThat(result.getComponentsList()).extracting(Component::getKey) - .containsExactly(Stream.of(project1, project2, project3).map(ComponentDto::getDbKey).toArray(String[]::new)); + .containsExactly(Stream.of(project1, project2, project3).map(ComponentDto::getKey).toArray(String[]::new)); } @Test @@ -664,7 +664,7 @@ public class SearchProjectsActionTest { assertThat(result.getComponentsList()).extracting(Component::getKey) .containsExactly( Stream.of(application1, application2, application3) - .map(ComponentDto::getDbKey) + .map(ComponentDto::getKey) .toArray(String[]::new)); } @@ -691,7 +691,7 @@ public class SearchProjectsActionTest { assertThat(result.getComponentsList()).extracting(Component::getKey) .containsExactly( Stream.of(project1, project2, project3) - .map(ComponentDto::getDbKey) + .map(ComponentDto::getKey) .toArray(String[]::new)); } @@ -1160,9 +1160,9 @@ public class SearchProjectsActionTest { index(); assertThat(call(request.setSort(COVERAGE).setAsc(true)).getComponentsList()).extracting(Component::getKey) - .containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey()); + .containsExactly(project3.getKey(), project4.getKey(), project2.getKey(), project1.getKey()); assertThat(call(request.setSort(COVERAGE).setAsc(false)).getComponentsList()).extracting(Component::getKey) - .containsExactly(project2.getDbKey(), project1.getDbKey(), project3.getDbKey(), project4.getDbKey()); + .containsExactly(project2.getKey(), project1.getKey(), project3.getKey(), project4.getKey()); } @Test @@ -1176,33 +1176,33 @@ public class SearchProjectsActionTest { index(); assertThat(call(request.setSort(QUALITY_GATE_STATUS).setAsc(true)).getComponentsList()).extracting(Component::getKey) - .containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey()); + .containsExactly(project3.getKey(), project4.getKey(), project2.getKey(), project1.getKey()); assertThat(call(request.setSort(QUALITY_GATE_STATUS).setAsc(false)).getComponentsList()).extracting(Component::getKey) - .containsExactly(project2.getDbKey(), project1.getDbKey(), project3.getDbKey(), project4.getDbKey()); + .containsExactly(project2.getKey(), project1.getKey(), project3.getKey(), project4.getKey()); } @Test public void sort_by_last_analysis_date() { userSession.logIn(); - ComponentDto project1 = db.components().insertPublicProject(p -> p.setDbKey("project1")); + ComponentDto project1 = db.components().insertPublicProject(p -> p.setKey("project1")); authorizationIndexerTester.allowOnlyAnyone(project1); - ComponentDto project2 = db.components().insertPublicProject(p -> p.setDbKey("project2")); + ComponentDto project2 = db.components().insertPublicProject(p -> p.setKey("project2")); db.components().insertSnapshot(project2, snapshot -> snapshot.setCreatedAt(40_000_000_000L).setLast(true)); authorizationIndexerTester.allowOnlyAnyone(project2); - ComponentDto project3 = db.components().insertPublicProject(p -> p.setDbKey("project3")); + ComponentDto project3 = db.components().insertPublicProject(p -> p.setKey("project3")); db.components().insertSnapshot(project3, snapshot -> snapshot.setCreatedAt(20_000_000_000L).setLast(true)); authorizationIndexerTester.allowOnlyAnyone(project3); - ComponentDto project4 = db.components().insertPublicProject(p -> p.setDbKey("project4")); + ComponentDto project4 = db.components().insertPublicProject(p -> p.setKey("project4")); db.components().insertSnapshot(project4, snapshot -> snapshot.setCreatedAt(10_000_000_000L).setLast(false)); db.components().insertSnapshot(project4, snapshot -> snapshot.setCreatedAt(30_000_000_000L).setLast(true)); authorizationIndexerTester.allowOnlyAnyone(project4); index(); assertThat(call(request.setSort(ANALYSIS_DATE).setAsc(true)).getComponentsList()).extracting(Component::getKey) - .containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey()); + .containsExactly(project3.getKey(), project4.getKey(), project2.getKey(), project1.getKey()); assertThat(call(request.setSort(ANALYSIS_DATE).setAsc(false)).getComponentsList()).extracting(Component::getKey) - .containsExactly(project2.getDbKey(), project4.getDbKey(), project3.getDbKey(), project1.getDbKey()); + .containsExactly(project2.getKey(), project4.getKey(), project3.getKey(), project1.getKey()); } @Test @@ -1224,9 +1224,9 @@ public class SearchProjectsActionTest { assertThat(result.getComponentsList()).extracting(Component::getKey, Component::hasAnalysisDate, Component::getAnalysisDate) .containsOnly( - tuple(project1.getDbKey(), true, formatDateTime(new Date(20_000_000_000L))), - tuple(project2.getDbKey(), true, formatDateTime(new Date(30_000_000_000L))), - tuple(project3.getDbKey(), false, "")); + tuple(project1.getKey(), true, formatDateTime(new Date(20_000_000_000L))), + tuple(project2.getKey(), true, formatDateTime(new Date(30_000_000_000L))), + tuple(project3.getKey(), false, "")); } @Test @@ -1256,10 +1256,10 @@ public class SearchProjectsActionTest { assertThat(result.getComponentsList()).extracting(Component::getKey, Component::hasLeakPeriodDate, Component::getLeakPeriodDate) .containsOnly( - tuple(project1.getDbKey(), true, formatDateTime(new Date(10_000_000_000L))), - tuple(project2.getDbKey(), false, ""), - tuple(project3.getDbKey(), false, ""), - tuple(application1.getDbKey(), true, formatDateTime(new Date(10_000_000_000L)))); + tuple(project1.getKey(), true, formatDateTime(new Date(10_000_000_000L))), + tuple(project2.getKey(), false, ""), + tuple(project3.getKey(), false, ""), + tuple(application1.getKey(), true, formatDateTime(new Date(10_000_000_000L)))); } @Test @@ -1275,8 +1275,8 @@ public class SearchProjectsActionTest { assertThat(result.getComponentsList()).extracting(Component::getKey, Component::getVisibility) .containsExactly( - tuple(privateProject.getDbKey(), privateProject.isPrivate() ? "private" : "public"), - tuple(publicProject.getDbKey(), publicProject.isPrivate() ? "private" : "public")); + tuple(privateProject.getKey(), privateProject.isPrivate() ? "private" : "public"), + tuple(publicProject.getKey(), publicProject.isPrivate() ? "private" : "public")); } @Test @@ -1289,7 +1289,7 @@ public class SearchProjectsActionTest { SearchProjectsWsResponse result = call(request); assertThat(result.getComponentsList()).extracting(Component::getKey) - .containsExactlyInAnyOrder(project.getDbKey()); + .containsExactlyInAnyOrder(project.getKey()); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java index 169ceccf252..6603f2a0197 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java @@ -125,9 +125,9 @@ public class ShowActionTest { db.components().insertProjectAndSnapshot(project); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(project.getDbKey()); + ShowWsResponse response = newRequest(project.getKey()); - assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); + assertThat(response.getComponent().getKey()).isEqualTo(project.getKey()); } @Test @@ -138,10 +138,10 @@ public class ShowActionTest { ComponentDto file = db.components().insertComponent(newFileDto(directory)); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(file.getDbKey()); + ShowWsResponse response = newRequest(file.getKey()); - assertThat(response.getComponent().getKey()).isEqualTo(file.getDbKey()); - assertThat(response.getAncestorsList()).extracting(Component::getKey).containsOnly(directory.getDbKey(), module.getDbKey(), project.getDbKey()); + assertThat(response.getComponent().getKey()).isEqualTo(file.getKey()); + assertThat(response.getAncestorsList()).extracting(Component::getKey).containsOnly(directory.getKey(), module.getKey(), project.getKey()); } @Test @@ -150,9 +150,9 @@ public class ShowActionTest { db.components().insertComponent(newModuleDto(project)); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(project.getDbKey()); + ShowWsResponse response = newRequest(project.getKey()); - assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); + assertThat(response.getComponent().getKey()).isEqualTo(project.getKey()); assertThat(response.getAncestorsList()).isEmpty(); } @@ -165,7 +165,7 @@ public class ShowActionTest { newAnalysis(project).setCreatedAt(3_000_000_000L).setLast(true)); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(project.getDbKey()); + ShowWsResponse response = newRequest(project.getKey()); assertThat(response.getComponent().getAnalysisDate()).isNotEmpty().isEqualTo(formatDateTime(new Date(3_000_000_000L))); } @@ -180,7 +180,7 @@ public class ShowActionTest { userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(project.getDbKey()); + ShowWsResponse response = newRequest(project.getKey()); assertThat(response.getComponent().getLeakPeriodDate()).isNotEmpty().isEqualTo(formatDateTime(new Date(3_000_000_000L))); } @@ -194,7 +194,7 @@ public class ShowActionTest { ComponentDto file = db.components().insertComponent(newFileDto(directory)); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(file.getDbKey()); + ShowWsResponse response = newRequest(file.getKey()); String expectedDate = formatDateTime(new Date(3_000_000_000L)); assertThat(response.getAncestorsList()).extracting(Component::getAnalysisDate) @@ -206,7 +206,7 @@ public class ShowActionTest { ComponentDto privateProject = db.components().insertPrivateProject(); userSession.addProjectPermission(USER, privateProject); - ShowWsResponse result = newRequest(privateProject.getDbKey()); + ShowWsResponse result = newRequest(privateProject.getKey()); assertThat(result.getComponent().hasVisibility()).isTrue(); assertThat(result.getComponent().getVisibility()).isEqualTo("private"); } @@ -216,7 +216,7 @@ public class ShowActionTest { ComponentDto publicProject = db.components().insertPublicProject(); userSession.registerComponents(publicProject); - ShowWsResponse result = newRequest(publicProject.getDbKey()); + ShowWsResponse result = newRequest(publicProject.getKey()); assertThat(result.getComponent().hasVisibility()).isTrue(); assertThat(result.getComponent().getVisibility()).isEqualTo("public"); } @@ -226,7 +226,7 @@ public class ShowActionTest { ComponentDto view = db.components().insertPrivatePortfolio(); userSession.addProjectPermission(USER, view); - ShowWsResponse result = newRequest(view.getDbKey()); + ShowWsResponse result = newRequest(view.getKey()); assertThat(result.getComponent().hasVisibility()).isTrue(); } @@ -236,7 +236,7 @@ public class ShowActionTest { userSession.addProjectPermission(USER, privateProject); ComponentDto module = db.components().insertComponent(newModuleDto(privateProject)); - ShowWsResponse result = newRequest(module.getDbKey()); + ShowWsResponse result = newRequest(module.getKey()); assertThat(result.getComponent().hasVisibility()).isFalse(); } @@ -249,7 +249,7 @@ public class ShowActionTest { db.components().insertSnapshot(project, s -> s.setProjectVersion("1.1")); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(file.getDbKey()); + ShowWsResponse response = newRequest(file.getKey()); assertThat(response.getComponent().getVersion()).isEqualTo("1.1"); assertThat(response.getAncestorsList()) @@ -379,7 +379,7 @@ public class ShowActionTest { ComponentDto componentDto = newPrivateProjectDto("project-uuid"); db.components().insertProjectAndSnapshot(componentDto); - String componentDtoDbKey = componentDto.getDbKey(); + String componentDtoDbKey = componentDto.getKey(); assertThatThrownBy(() -> newRequest(componentDtoDbKey)) .isInstanceOf(ForbiddenException.class); } @@ -396,7 +396,7 @@ public class ShowActionTest { ComponentDto privateProjectDto = newPrivateProjectDto(); ComponentDto project = db.components().insertComponent(privateProjectDto); userSession.addProjectPermission(USER, project); - db.components().insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false)); + db.components().insertComponent(newFileDto(project).setKey("file-key").setEnabled(false)); assertThatThrownBy(() -> newRequest("file-key")) .isInstanceOf(NotFoundException.class) @@ -426,10 +426,10 @@ public class ShowActionTest { ComponentDto branch = db.components().insertProjectBranch(project); TestRequest request = ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getDbKey()); + .setParam(PARAM_COMPONENT, branch.getKey()); assertThatThrownBy(() -> request.executeProtobuf(ShowWsResponse.class)) .isInstanceOf(NotFoundException.class) - .hasMessage(String.format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(String.format("Component key '%s' not found", branch.getKey())); } private ShowWsResponse newRequest(@Nullable String key) { @@ -442,8 +442,8 @@ public class ShowActionTest { private void insertJsonExampleComponentsAndSnapshots() { ComponentDto project = db.components().insertPrivateProject(c -> c.setUuid("AVIF98jgA3Ax6PH2efOW") - .setProjectUuid("AVIF98jgA3Ax6PH2efOW") - .setDbKey("com.sonarsource:java-markdown") + .setBranchUuid("AVIF98jgA3Ax6PH2efOW") + .setKey("com.sonarsource:java-markdown") .setName("Java Markdown") .setDescription("Java Markdown Project") .setQualifier(Qualifiers.PROJECT), @@ -454,13 +454,13 @@ public class ShowActionTest { .setCreatedAt(parseDateTime("2017-03-01T11:39:03+0100").getTime()) .setPeriodDate(parseDateTime("2017-01-01T11:39:03+0100").getTime())); ComponentDto directory = newDirectory(project, "AVIF-FfgA3Ax6PH2efPF", "src/main/java/com/sonarsource/markdown/impl") - .setDbKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl") + .setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl") .setName("src/main/java/com/sonarsource/markdown/impl") .setQualifier(Qualifiers.DIRECTORY); db.components().insertComponent(directory); db.components().insertComponent( newFileDto(directory, directory, "AVIF-FffA3Ax6PH2efPD") - .setDbKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java") + .setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java") .setName("Rule.java") .setPath("src/main/java/com/sonarsource/markdown/impl/Rule.java") .setLanguage("java") diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java index 862404efcf6..7f14288969d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java @@ -132,15 +132,15 @@ public class SuggestionsActionTest { @Test public void test_example_json_response() { - ComponentDto project1 = db.components().insertPublicProject(p -> p.setDbKey("org.sonarsource:sonarqube").setName("SonarSource :: SonarQube")); - ComponentDto project2 = db.components().insertPublicProject(p -> p.setDbKey("org.sonarsource:sonarlint").setName("SonarSource :: SonarLint")); + ComponentDto project1 = db.components().insertPublicProject(p -> p.setKey("org.sonarsource:sonarqube").setName("SonarSource :: SonarQube")); + ComponentDto project2 = db.components().insertPublicProject(p -> p.setKey("org.sonarsource:sonarlint").setName("SonarSource :: SonarLint")); componentIndexer.indexAll(); authorizationIndexerTester.allowOnlyAnyone(project1); authorizationIndexerTester.allowOnlyAnyone(project2); TestResponse wsResponse = ws.newRequest() .setParam(PARAM_QUERY, "Sonar") - .setParam(PARAM_RECENTLY_BROWSED, project1.getDbKey()) + .setParam(PARAM_RECENTLY_BROWSED, project1.getKey()) .setMethod("POST") .setMediaType(MediaTypes.JSON) .execute(); @@ -157,7 +157,7 @@ public class SuggestionsActionTest { SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()) + .setParam(PARAM_RECENTLY_BROWSED, project.getKey()) .executeProtobuf(SuggestionsWsResponse.class); // assert match in qualifier "TRK" @@ -170,7 +170,7 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey, Suggestion::getIsRecentlyBrowsed) - .containsExactly(tuple(project.getDbKey(), true)); + .containsExactly(tuple(project.getKey(), true)); } @Test @@ -181,7 +181,7 @@ public class SuggestionsActionTest { SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()) + .setParam(PARAM_RECENTLY_BROWSED, project.getKey()) .executeProtobuf(SuggestionsWsResponse.class); // assert match in qualifier "TRK" @@ -194,7 +194,7 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey, Suggestion::getIsRecentlyBrowsed) - .containsExactly(tuple(project.getDbKey(), true)); + .containsExactly(tuple(project.getKey(), true)); } @Test @@ -205,7 +205,7 @@ public class SuggestionsActionTest { SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()) + .setParam(PARAM_RECENTLY_BROWSED, project.getKey()) .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) @@ -235,7 +235,7 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey, Suggestion::getIsFavorite) - .containsExactly(tuple(project.getDbKey(), true)); + .containsExactly(tuple(project.getKey(), true)); } @Test @@ -264,7 +264,7 @@ public class SuggestionsActionTest { SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()) + .setParam(PARAM_RECENTLY_BROWSED, project.getKey()) .executeProtobuf(SuggestionsWsResponse.class); // assert match in qualifier "TRK" @@ -277,7 +277,7 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey, Suggestion::getIsFavorite, Suggestion::getIsRecentlyBrowsed) - .containsExactly(tuple(project.getDbKey(), true, true)); + .containsExactly(tuple(project.getKey(), true, true)); } @Test @@ -314,7 +314,7 @@ public class SuggestionsActionTest { SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_RECENTLY_BROWSED, Stream.of(project3, project1).map(ComponentDto::getDbKey).collect(joining(","))) + .setParam(PARAM_RECENTLY_BROWSED, Stream.of(project3, project1).map(ComponentDto::getKey).collect(joining(","))) .executeProtobuf(SuggestionsWsResponse.class); // assert order of keys @@ -331,12 +331,12 @@ public class SuggestionsActionTest { @Test public void suggestions_without_query_should_return_empty_qualifiers() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto()); - componentIndexer.indexOnAnalysis(project.projectUuid()); + componentIndexer.indexOnAnalysis(project.branchUuid()); userSessionRule.addProjectPermission(USER, project); SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()) + .setParam(PARAM_RECENTLY_BROWSED, project.getKey()) .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) @@ -349,12 +349,12 @@ public class SuggestionsActionTest { public void suggestions_should_filter_allowed_qualifiers() { resourceTypes.setAllQualifiers(PROJECT, MODULE, FILE, UNIT_TEST_FILE); ComponentDto project = db.components().insertComponent(newPrivateProjectDto()); - componentIndexer.indexOnAnalysis(project.projectUuid()); + componentIndexer.indexOnAnalysis(project.branchUuid()); userSessionRule.addProjectPermission(USER, project); SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()) + .setParam(PARAM_RECENTLY_BROWSED, project.getKey()) .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) @@ -371,7 +371,7 @@ public class SuggestionsActionTest { SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_QUERY, project.getDbKey()) + .setParam(PARAM_QUERY, project.getKey()) .executeProtobuf(SuggestionsWsResponse.class); // assert match in qualifier "TRK" @@ -384,7 +384,7 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey) - .containsExactly(project.getDbKey()); + .containsExactly(project.getKey()); } @Test @@ -399,7 +399,7 @@ public class SuggestionsActionTest { SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_QUERY, project.getDbKey()) + .setParam(PARAM_QUERY, project.getKey()) .executeProtobuf(SuggestionsWsResponse.class); // assert match in qualifier "TRK" @@ -449,14 +449,14 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey) - .contains(project.getDbKey()); + .contains(project.getKey()); assertThat(response.getWarning()).contains(SHORT_INPUT_WARNING); } @Test public void should_contain_component_names() { ComponentDto project1 = db.components().insertComponent(newPrivateProjectDto().setName("Project1")); - componentIndexer.indexOnAnalysis(project1.projectUuid()); + componentIndexer.indexOnAnalysis(project1.branchUuid()); authorizationIndexerTester.allowOnlyAnyone(project1); SuggestionsWsResponse response = ws.newRequest() @@ -467,7 +467,7 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey, Suggestion::getName) - .containsExactlyInAnyOrder(tuple(project1.getDbKey(), project1.name())); + .containsExactlyInAnyOrder(tuple(project1.getKey(), project1.name())); } @Test @@ -475,7 +475,7 @@ public class SuggestionsActionTest { ComponentDto project = db.components().insertComponent(newPrivateProjectDto().setName("ProjectWithModules")); db.components().insertComponent(newModuleDto(project).setName("Module1")); db.components().insertComponent(newModuleDto(project).setName("Module2")); - componentIndexer.indexOnAnalysis(project.projectUuid()); + componentIndexer.indexOnAnalysis(project.branchUuid()); authorizationIndexerTester.allowOnlyAnyone(project); SuggestionsWsResponse response = ws.newRequest() @@ -486,7 +486,7 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey) - .containsOnly(project.getDbKey()); + .containsOnly(project.getKey()); } @Test @@ -496,13 +496,13 @@ public class SuggestionsActionTest { db.components().insertComponent(module1); ComponentDto module2 = newModuleDto(project).setName("Module2"); db.components().insertComponent(module2); - componentIndexer.indexOnAnalysis(project.projectUuid()); + componentIndexer.indexOnAnalysis(project.branchUuid()); authorizationIndexerTester.allowOnlyAnyone(project); SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") .setParam(PARAM_QUERY, "Module") - .setParam(PARAM_RECENTLY_BROWSED, Stream.of(module1.getDbKey(), project.getDbKey()).collect(joining(","))) + .setParam(PARAM_RECENTLY_BROWSED, Stream.of(module1.getKey(), project.getKey()).collect(joining(","))) .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) @@ -517,8 +517,8 @@ public class SuggestionsActionTest { ComponentDto nonFavouriteProject = db.components().insertComponent(newPublicProjectDto().setName("Project2")); doReturn(singletonList(favouriteProject)).when(favoriteFinder).list(); - componentIndexer.indexOnAnalysis(favouriteProject.projectUuid()); - componentIndexer.indexOnAnalysis(nonFavouriteProject.projectUuid()); + componentIndexer.indexOnAnalysis(favouriteProject.branchUuid()); + componentIndexer.indexOnAnalysis(nonFavouriteProject.branchUuid()); authorizationIndexerTester.allowOnlyAnyone(favouriteProject, nonFavouriteProject); SuggestionsWsResponse response = ws.newRequest() @@ -529,13 +529,13 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey, Suggestion::getIsFavorite) - .containsExactly(tuple(favouriteProject.getDbKey(), true), tuple(nonFavouriteProject.getDbKey(), false)); + .containsExactly(tuple(favouriteProject.getKey(), true), tuple(nonFavouriteProject.getKey(), false)); } @Test public void should_return_empty_qualifiers() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto()); - componentIndexer.indexOnAnalysis(project.projectUuid()); + componentIndexer.indexOnAnalysis(project.branchUuid()); authorizationIndexerTester.allowOnlyAnyone(project); SuggestionsWsResponse response = ws.newRequest() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index cc893a5aaf5..3124ef11c26 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -118,7 +118,7 @@ public class TreeActionTest { logInWithBrowsePermission(project); String response = ws.newRequest() - .setParam(PARAM_COMPONENT, project.getDbKey()) + .setParam(PARAM_COMPONENT, project.getKey()) .execute() .getInput(); @@ -145,7 +145,7 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "children") - .setParam(PARAM_COMPONENT, module.getDbKey()) + .setParam(PARAM_COMPONENT, module.getKey()) .setParam(Param.PAGE, "2") .setParam(Param.PAGE_SIZE, "3") .setParam(Param.TEXT_QUERY, "file-name") @@ -175,7 +175,7 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "all") - .setParam(PARAM_COMPONENT, module.getDbKey()) + .setParam(PARAM_COMPONENT, module.getKey()) .setParam(Param.PAGE, "2") .setParam(Param.PAGE_SIZE, "3") .setParam(Param.TEXT_QUERY, "file-name") @@ -200,7 +200,7 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "all") .setParam(PARAM_QUALIFIERS, FILE) - .setParam(PARAM_COMPONENT, project.getDbKey()).executeProtobuf(TreeWsResponse.class); + .setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(TreeWsResponse.class); assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-1", "file-key-2"); } @@ -221,7 +221,7 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "leaves") - .setParam(PARAM_COMPONENT, project.getDbKey()) + .setParam(PARAM_COMPONENT, project.getKey()) .setParam(PARAM_QUALIFIERS, FILE).executeProtobuf(TreeWsResponse.class); assertThat(response.getComponentsCount()).isEqualTo(3); @@ -244,7 +244,7 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "all") .setParam(Param.SORT, "qualifier, name") - .setParam(PARAM_COMPONENT, project.getDbKey()).executeProtobuf(TreeWsResponse.class); + .setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(TreeWsResponse.class); assertThat(response.getComponentsList()).extracting("key").containsExactly("MODULE_KEY_module-uuid-1", "KEY_project-uuid:directory-uuid-1", "file-key-1", "file-key-2"); } @@ -253,7 +253,7 @@ public class TreeActionTest { public void project_reference_from_portfolio() { ComponentDto view = ComponentTesting.newPortfolio("view-uuid"); db.components().insertPortfolioAndSnapshot(view); - ComponentDto project = newPrivateProjectDto("project-uuid-1").setName("project-name").setDbKey("project-key-1"); + ComponentDto project = newPrivateProjectDto("project-uuid-1").setName("project-name").setKey("project-key-1"); db.components().insertProjectAndSnapshot(project); db.components().insertComponent(newProjectCopy("project-uuid-1-copy", project, view)); db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name")); @@ -263,7 +263,7 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "children") - .setParam(PARAM_COMPONENT, view.getDbKey()) + .setParam(PARAM_COMPONENT, view.getKey()) .setParam(Param.TEXT_QUERY, "name").executeProtobuf(TreeWsResponse.class); assertThat(response.getComponentsList()).extracting("key").containsExactly("KEY_view-uuidproject-key-1", "sub-view-key"); @@ -273,12 +273,12 @@ public class TreeActionTest { @Test public void project_branch_reference_from_application_branch() { - ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setDbKey("app-key")); + ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app-key")); ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey("app-branch")); - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("project-key")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key")); ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch")); ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch) - .setDbKey(applicationBranch.getKey() + applicationBranch.getBranch() + projectBranch.getDbKey())); + .setKey(applicationBranch.getKey() + applicationBranch.getBranch() + projectBranch.getKey())); logInWithBrowsePermission(application); TreeWsResponse result = ws.newRequest() @@ -300,9 +300,9 @@ public class TreeActionTest { logInWithBrowsePermission(project); TreeWsResponse response = ws.newRequest() - .setParam(PARAM_COMPONENT, project.getDbKey()).executeProtobuf(TreeWsResponse.class); + .setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(TreeWsResponse.class); - assertThat(response.getBaseComponent().getKey()).isEqualTo(project.getDbKey()); + assertThat(response.getBaseComponent().getKey()).isEqualTo(project.getKey()); assertThat(response.getComponentsList()).isEmpty(); assertThat(response.getPaging().getTotal()).isZero(); assertThat(response.getPaging().getPageSize()).isEqualTo(100); @@ -320,13 +320,13 @@ public class TreeActionTest { .registerComponents(project, view); TreeWsResponse response = ws.newRequest() - .setParam(PARAM_COMPONENT, view.getDbKey()) + .setParam(PARAM_COMPONENT, view.getKey()) .executeProtobuf(TreeWsResponse.class); - assertThat(response.getBaseComponent().getKey()).isEqualTo(view.getDbKey()); + assertThat(response.getBaseComponent().getKey()).isEqualTo(view.getKey()); assertThat(response.getComponentsCount()).isOne(); - assertThat(response.getComponents(0).getKey()).isEqualTo(projectCopy.getDbKey()); - assertThat(response.getComponents(0).getRefKey()).isEqualTo(project.getDbKey()); + assertThat(response.getComponents(0).getKey()).isEqualTo(projectCopy.getKey()); + assertThat(response.getComponents(0).getRefKey()).isEqualTo(project.getKey()); } @Test @@ -382,10 +382,10 @@ public class TreeActionTest { ComponentDto branch = db.components().insertProjectBranch(project); TestRequest request = ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getDbKey()); + .setParam(PARAM_COMPONENT, branch.getKey()); assertThatThrownBy(() -> request.executeProtobuf(Components.ShowWsResponse.class)) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } @Test @@ -395,10 +395,10 @@ public class TreeActionTest { ComponentDto branch = db.components().insertProjectBranch(project); TestRequest request = ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getDbKey()); + .setParam(PARAM_COMPONENT, branch.getKey()); assertThatThrownBy(() -> request.executeProtobuf(Components.ShowWsResponse.class)) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } @Test @@ -409,7 +409,7 @@ public class TreeActionTest { db.commit(); TestRequest request = ws.newRequest() - .setParam(PARAM_COMPONENT, project.getDbKey()); + .setParam(PARAM_COMPONENT, project.getKey()); assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class); } @@ -420,7 +420,7 @@ public class TreeActionTest { db.commit(); TestRequest request = ws.newRequest() - .setParam(PARAM_COMPONENT, project.getDbKey()) + .setParam(PARAM_COMPONENT, project.getKey()) .setParam(Param.PAGE_SIZE, "501"); assertThatThrownBy(request::execute) @@ -434,7 +434,7 @@ public class TreeActionTest { db.commit(); TestRequest request = ws.newRequest() - .setParam(PARAM_COMPONENT, project.getDbKey()) + .setParam(PARAM_COMPONENT, project.getKey()) .setParam(Param.TEXT_QUERY, "fi"); assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) @@ -476,7 +476,7 @@ public class TreeActionTest { @Test public void fail_when_base_component_is_removed() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto()); - db.components().insertComponent(ComponentTesting.newFileDto(project).setDbKey("file-key").setEnabled(false)); + db.components().insertComponent(ComponentTesting.newFileDto(project).setKey("file-key").setEnabled(false)); logInWithBrowsePermission(project); TestRequest request = ws.newRequest() @@ -511,7 +511,7 @@ public class TreeActionTest { private static ComponentDto newFileDto(ComponentDto moduleOrProject, @Nullable ComponentDto directory, int i) { return ComponentTesting.newFileDto(moduleOrProject, directory, "file-uuid-" + i) .setName("file-name-" + i) - .setDbKey("file-key-" + i) + .setKey("file-key-" + i) .setPath("file-path-" + i); } @@ -522,9 +522,9 @@ public class TreeActionTest { private ComponentDto initJsonExampleComponents() throws IOException { ComponentDto project = db.components().insertPrivateProject(c -> c.setUuid("MY_PROJECT_ID") .setDescription("MY_PROJECT_DESCRIPTION") - .setDbKey("MY_PROJECT_KEY") + .setKey("MY_PROJECT_KEY") .setName("Project Name") - .setProjectUuid("MY_PROJECT_ID"), + .setBranchUuid("MY_PROJECT_ID"), p -> p.setTagsString("abc,def")); db.components().insertSnapshot(project); @@ -537,7 +537,7 @@ public class TreeActionTest { JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject(); String uuid = format("child-component-uuid-%d", i); db.components().insertComponent(newChildComponent(uuid, project, project) - .setDbKey(getJsonField(componentAsJsonObject, "key")) + .setKey(getJsonField(componentAsJsonObject, "key")) .setName(getJsonField(componentAsJsonObject, "name")) .setLanguage(getJsonField(componentAsJsonObject, "language")) .setPath(getJsonField(componentAsJsonObject, "path")) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionNewIssuesTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionNewIssuesTest.java index 0882301f62d..0aa1331da6b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionNewIssuesTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionNewIssuesTest.java @@ -151,7 +151,7 @@ public class SearchEventsActionNewIssuesTest { @Test public void return_link_to_issue_search_for_new_issues_event() { userSession.logIn("my_login"); - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("my_project")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("my_project")); userSession.addProjectPermission(USER, project); SnapshotDto analysis = insertAnalysis(project, 1_400_000_000_000L); insertIssue(project, analysis); @@ -240,7 +240,7 @@ public class SearchEventsActionNewIssuesTest { public void encode_link() { userSession.logIn("rågnar").setSystemAdministrator(); long from = 1_500_000_000_000L; - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("M&M's")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("M&M's")); userSession.addProjectPermission(USER, project); SnapshotDto analysis = insertAnalysis(project, from); insertIssue(project, analysis); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionQualityGateTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionQualityGateTest.java index 2247ab7da89..03d72252460 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionQualityGateTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionQualityGateTest.java @@ -173,7 +173,7 @@ public class SearchEventsActionQualityGateTest { @Test public void encode_link() { - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("M&M's")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("M&M's")); userSession.addProjectPermission(USER, project); SnapshotDto analysis = insertSuccessfulActivity(project, 1_500_000_000_000L); EventDto event = db.events().insertEvent(newQualityGateEvent(analysis).setName("Failed").setDate(analysis.getCreatedAt())); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionTest.java index 7a793283dc7..b8e93f8d6af 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionTest.java @@ -107,7 +107,7 @@ public class SearchEventsActionTest { @Test public void json_example() { - ComponentDto project = db.components().insertPrivateProject(p -> p.setName("My Project").setDbKey(KeyExamples.KEY_PROJECT_EXAMPLE_001)); + ComponentDto project = db.components().insertPrivateProject(p -> p.setName("My Project").setKey(KeyExamples.KEY_PROJECT_EXAMPLE_001)); userSession.addProjectPermission(USER, project); SnapshotDto analysis = insertAnalysis(project, 1_500_000_000_000L); EventDto e1 = db.events().insertEvent(newQualityGateEvent(analysis).setName("Failed").setDate(analysis.getCreatedAt())); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java index 2259a8bf7d1..629d0ca0e12 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java @@ -57,7 +57,7 @@ public class DuplicationsParserTest { " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + " </g>\n" + - "</duplications>", file.getDbKey(), file.getDbKey())); + "</duplications>", file.getKey(), file.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -86,7 +86,7 @@ public class DuplicationsParserTest { " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + " </g>\n" + - "</duplications>", file2.getDbKey(), file1.getDbKey())); + "</duplications>", file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -118,7 +118,7 @@ public class DuplicationsParserTest { " <b s=\"137\" l=\"24\" r=\"%s\"/>\n" + " <b s=\"111\" l=\"24\" r=\"%s\"/>\n" + " </g>\n" + - "</duplications>", file1.getDbKey(), fileOnProject2.getDbKey(), file2.getDbKey())); + "</duplications>", file1.getKey(), fileOnProject2.getKey(), file2.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -148,11 +148,11 @@ public class DuplicationsParserTest { public void duplications_on_many_blocks() { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto file1 = db.components().insertComponent(newFileDto(project1) - .setDbKey("org.codehaus.sonar:sonar-plugin-api:src/main/java/org/sonar/api/utils/command/CommandExecutor.java") + .setKey("org.codehaus.sonar:sonar-plugin-api:src/main/java/org/sonar/api/utils/command/CommandExecutor.java") .setLongName("CommandExecutor")); ComponentDto project2 = db.components().insertPrivateProject(); ComponentDto file2 = db.components().insertComponent(newFileDto(project2) - .setDbKey("com.sonarsource.orchestrator:sonar-orchestrator:src/main/java/com/sonar/orchestrator/util/CommandExecutor.java") + .setKey("com.sonarsource.orchestrator:sonar-orchestrator:src/main/java/com/sonar/orchestrator/util/CommandExecutor.java") .setLongName("CommandExecutor")); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, null, null, format("<duplications>\n" + @@ -164,7 +164,7 @@ public class DuplicationsParserTest { " <b s=\"38\" l=\"40\" r=\"%s\"/>\n" + " <b s=\"29\" l=\"39\" r=\"%s\"/>\n" + " </g>\n" + - "</duplications>\n", file2.getDbKey(), file1.getDbKey(), file2.getDbKey(), file1.getDbKey())); + "</duplications>\n", file2.getKey(), file1.getKey(), file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(2); // Block with smaller line should come first @@ -186,7 +186,7 @@ public class DuplicationsParserTest { " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + " </g>\n" + - "</duplications>", file.getDbKey(), "not_existing")); + "</duplications>", file.getKey(), "not_existing")); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -198,7 +198,7 @@ public class DuplicationsParserTest { assertThat(duplication1.from()).isEqualTo(31); assertThat(duplication1.size()).isEqualTo(5); - Duplication duplication2 = duplication(duplications, file.getDbKey()); + Duplication duplication2 = duplication(duplications, file.getKey()); assertThat(duplication2.componentDto()).isEqualTo(file); assertThat(duplication2.from()).isEqualTo(20); assertThat(duplication2.size()).isEqualTo(5); @@ -212,7 +212,7 @@ public class DuplicationsParserTest { ComponentDto fileOnSameProject = db.components().insertComponent(newFileDto(project1, null)); ComponentDto fileOnDifferentProject = db.components().insertComponent(newFileDto(project2, null)); - DuplicationsParser.DuplicationComparator comparator = new DuplicationsParser.DuplicationComparator(currentFile.uuid(), currentFile.projectUuid()); + DuplicationsParser.DuplicationComparator comparator = new DuplicationsParser.DuplicationComparator(currentFile.uuid(), currentFile.branchUuid()); // On same file assertThat(comparator.compare(Duplication.newComponent(currentFile, 2, 2), @@ -256,7 +256,7 @@ public class DuplicationsParserTest { " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + " </g>\n" + - "</duplications>", file2.getDbKey(), file1.getDbKey())); + "</duplications>", file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -288,7 +288,7 @@ public class DuplicationsParserTest { " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + " </g>\n" + - "</duplications>", file2.getDbKey(), file1.getDbKey())); + "</duplications>", file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -310,7 +310,7 @@ public class DuplicationsParserTest { private static Duplication duplication(List<Duplication> duplications, @Nullable final String componentKey) { return Iterables.find(duplications, input -> input != null && (componentKey == null ? input.componentDto() == null - : input.componentDto() != null && componentKey.equals(input.componentDto().getDbKey()))); + : input.componentDto() != null && componentKey.equals(input.componentDto().getKey()))); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java index 1b6ca037960..ccfcd558cd2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java @@ -82,18 +82,18 @@ public class ShowActionTest { @Test public void get_duplications_by_file_key() { TestRequest request = newBaseRequest(); - verifyCallToFileWithDuplications(file -> request.setParam("key", file.getDbKey())); + verifyCallToFileWithDuplications(file -> request.setParam("key", file.getKey())); } @Test public void return_file_with_missing_duplication_data() { ComponentDto project = db.components().insertPrivateProject(); - ComponentDto file = db.components().insertComponent(newFileDto(project).setDbKey("foo.js")); + ComponentDto file = db.components().insertComponent(newFileDto(project).setKey("foo.js")); db.components().insertSnapshot(newAnalysis(project)); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); - TestResponse result = newBaseRequest().setParam("key", file.getDbKey()).execute(); + TestResponse result = newBaseRequest().setParam("key", file.getKey()).execute(); assertJson(result.getInput()).isSimilarTo("{\n" + " \"duplications\": [],\n" + @@ -112,7 +112,7 @@ public class ShowActionTest { " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + " </g>\n" + - "</duplications>\n", file.getDbKey(), file.getDbKey()))); + "</duplications>\n", file.getKey(), file.getKey()))); String result = ws.newRequest() .setParam("key", file.getKey()) @@ -164,7 +164,7 @@ public class ShowActionTest { " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + " </g>\n" + - "</duplications>\n", file.getDbKey(), file.getDbKey()))); + "</duplications>\n", file.getKey(), file.getKey()))); String result = ws.newRequest() .setParam("key", file.getKey()) @@ -217,7 +217,7 @@ public class ShowActionTest { public void fail_if_user_is_not_allowed_to_access_project() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - TestRequest request = newBaseRequest().setParam("key", file.getDbKey()); + TestRequest request = newBaseRequest().setParam("key", file.getKey()); assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class); @@ -238,11 +238,11 @@ public class ShowActionTest { userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); ComponentDto branch = db.components().insertProjectBranch(project); TestRequest request = ws.newRequest() - .setParam("key", branch.getDbKey()); + .setParam("key", branch.getKey()); assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } private TestRequest newBaseRequest() { @@ -252,7 +252,7 @@ public class ShowActionTest { private void verifyCallToFileWithDuplications(Function<ComponentDto, TestRequest> requestFactory) { ComponentDto project = db.components().insertPrivateProject(); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); - ComponentDto file = db.components().insertComponent(newFileDto(project).setDbKey("foo.js")); + ComponentDto file = db.components().insertComponent(newFileDto(project).setKey("foo.js")); String xml = "<duplications>\n" + " <g>\n" + " <b s=\"31\" l=\"5\" r=\"foo.js\"/>\n" + diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java index fd86d0131fb..a23e1c3e420 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java @@ -117,9 +117,9 @@ public class AddActionTest { UserDto user = db.users().insertUser(); userSession.logIn(user).addProjectPermission(USER, project); - assertThatThrownBy(() -> call(branch.getDbKey())) + assertThatThrownBy(() -> call(branch.getKey())) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java index 0373bd7eb86..54d1083cc3a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java @@ -110,7 +110,7 @@ public class RemoveActionTest { ComponentDto project = db.components().insertPrivateProject(); userSession.logIn().addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); - String branchKey = branch.getDbKey(); + String branchKey = branch.getKey(); assertThatThrownBy(() -> call(branchKey)) .isInstanceOf(NotFoundException.class) @@ -129,7 +129,7 @@ public class RemoveActionTest { } private ComponentDto insertProject() { - return db.components().insertComponent(newPrivateProjectDto(PROJECT_UUID).setDbKey(PROJECT_KEY)); + return db.components().insertComponent(newPrivateProjectDto(PROJECT_UUID).setKey(PROJECT_KEY)); } private ComponentDto insertProjectAndPermissions() { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java index 47aeea71999..337df2043e7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java @@ -76,10 +76,10 @@ public class SearchActionTest { @Test public void return_favorites() { - ComponentDto project = newPrivateProjectDto("P1").setDbKey("K1").setName("N1"); + ComponentDto project = newPrivateProjectDto("P1").setKey("K1").setName("N1"); addComponent(project); - addComponent(newFileDto(project).setDbKey("K11").setName("N11")); - addComponent(newPrivateProjectDto("P2").setDbKey("K2").setName("N2")); + addComponent(newFileDto(project).setKey("K11").setName("N11")); + addComponent(newPrivateProjectDto("P2").setKey("K2").setName("N2")); SearchResponse result = call(); @@ -104,7 +104,7 @@ public class SearchActionTest { @Test public void filter_authorized_components() { - addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1")); + addComponent(ComponentTesting.newPrivateProjectDto().setKey("K1")); ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto()); db.favorites().add(unauthorizedProject, userUuid, userLogin); @@ -117,7 +117,7 @@ public class SearchActionTest { @Test public void paginate_results() { IntStream.rangeClosed(1, 9) - .forEach(i -> addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K" + i).setName("N" + i))); + .forEach(i -> addComponent(ComponentTesting.newPrivateProjectDto().setKey("K" + i).setName("N" + i))); ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto()); db.favorites().add(unauthorizedProject, userUuid, userLogin); @@ -132,8 +132,8 @@ public class SearchActionTest { @Test public void return_only_users_favorite() { - addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1")); - ComponentDto otherUserFavorite = ComponentTesting.newPrivateProjectDto().setDbKey("K42"); + addComponent(ComponentTesting.newPrivateProjectDto().setKey("K1")); + ComponentDto otherUserFavorite = ComponentTesting.newPrivateProjectDto().setKey("K42"); db.components().insertComponent(otherUserFavorite); db.favorites().add(otherUserFavorite, "42", userLogin); db.commit(); @@ -157,9 +157,9 @@ public class SearchActionTest { @Test public void json_example() { - addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1").setName("Samba")); - addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K2").setName("Apache HBase")); - addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K3").setName("JDK9")); + addComponent(ComponentTesting.newPrivateProjectDto().setKey("K1").setName("Samba")); + addComponent(ComponentTesting.newPrivateProjectDto().setKey("K2").setName("Apache HBase")); + addComponent(ComponentTesting.newPrivateProjectDto().setKey("K3").setName("JDK9")); String result = ws.newRequest().execute().getInput(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java index 951f51c00ac..38b9cc4eb41 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java @@ -725,7 +725,7 @@ public class SearchActionTest { .extracting(SearchWsResponse.Hotspot::getKey) .containsExactlyInAnyOrder(Arrays.stream(hotspotPR).map(IssueDto::getKey).toArray(String[]::new)); - verify(issueIndexSyncProgressChecker, times(3)).checkIfComponentNeedIssueSync(any(), eq(project.getDbKey())); + verify(issueIndexSyncProgressChecker, times(3)).checkIfComponentNeedIssueSync(any(), eq(project.getKey())); } @Test @@ -1920,11 +1920,11 @@ public class SearchActionTest { ComponentDto project = dbTester.components().insertPublicProject(componentDto -> componentDto .setName("test-project") .setLongName("test-project") - .setDbKey("com.sonarsource:test-project")); + .setKey("com.sonarsource:test-project")); userSessionRule.registerComponents(project); indexPermissions(); ComponentDto fileWithHotspot = dbTester.components().insertComponent(newFileDto(project) - .setDbKey("com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java") + .setKey("com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java") .setName("FourthClass.java") .setLongName("src/main/java/com/sonarsource/FourthClass.java") .setPath("src/main/java/com/sonarsource/FourthClass.java")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java index 1b89f229f3a..eef8d335517 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java @@ -1065,13 +1065,13 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(componentDto -> componentDto .setName("test-project") .setLongName("test-project") - .setDbKey("com.sonarsource:test-project")); + .setKey("com.sonarsource:test-project")); userSessionRule.registerComponents(project) .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project); ComponentDto file = dbTester.components().insertComponent( newFileDto(project) - .setDbKey("com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java") + .setKey("com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java") .setName("FourthClass.java") .setLongName("src/main/java/com/sonarsource/FourthClass.java") .setPath("src/main/java/com/sonarsource/FourthClass.java")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java index 36837d49920..29b0d0f7a2b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java @@ -206,7 +206,7 @@ public class PullTaintActionTest { @Test public void givenValidProjectKeyAndOneTaintOnBranch_returnOneTaint_WithMetadataSeverity() throws IOException { - loginWithBrowsePermission(correctProject.projectUuid(), correctFile.uuid()); + loginWithBrowsePermission(correctProject.branchUuid(), correctFile.uuid()); DbCommons.TextRange textRange = DbCommons.TextRange.newBuilder() .setStartLine(1) .setEndLine(2) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java index 9edd790d12f..26a262a21e0 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java @@ -167,8 +167,8 @@ public class SearchActionComponentsTest { @Test public void search_since_leak_period_on_project() { - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1")); db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime())); RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); IssueDto issueAfterLeak = db.issues().insertIssue(rule, project, file, i -> i.setKee(UUID_EXAMPLE_01) @@ -181,7 +181,7 @@ public class SearchActionComponentsTest { indexIssues(); ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, project.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, project.getKey()) .setParam(PARAM_SINCE_LEAK_PERIOD, "true") .execute() .assertJson(this.getClass(), "search_since_leak_period.json"); @@ -189,9 +189,9 @@ public class SearchActionComponentsTest { @Test public void search_since_leak_period_on_file_in_module_project() { - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")); ComponentDto module = db.components().insertComponent(newModuleDto(project)); - ComponentDto file = db.components().insertComponent(newFileDto(module, null, "F1").setDbKey("FK1")); + ComponentDto file = db.components().insertComponent(newFileDto(module, null, "F1").setKey("FK1")); db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime())); RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); IssueDto issueAfterLeak = db.issues().insertIssue(rule, project, file, i -> i.setKee(UUID_EXAMPLE_01) @@ -204,7 +204,7 @@ public class SearchActionComponentsTest { indexIssues(); ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, project.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, project.getKey()) .setParam(PARAM_FILES, file.path()) .setParam(PARAM_SINCE_LEAK_PERIOD, "true") .execute() @@ -213,8 +213,8 @@ public class SearchActionComponentsTest { @Test public void search_by_file_uuid() { - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1")); RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); allowAnyoneOnProjects(project); @@ -233,9 +233,9 @@ public class SearchActionComponentsTest { @Test public void search_by_file_key() { - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); - ComponentDto unitTest = db.components().insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setDbKey("FK2")); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1")); + ComponentDto unitTest = db.components().insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setKey("FK2")); RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); IssueDto issueOnFile = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); IssueDto issueOnTest = db.issues().insertIssue(rule, project, unitTest, i -> i.setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4")); @@ -255,9 +255,9 @@ public class SearchActionComponentsTest { @Test public void search_by_directory_path() { - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")); ComponentDto directory = db.components().insertComponent(newDirectory(project, "D1", "src/main/java/dir")); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1").setPath(directory.path() + "/MyComponent.java")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1").setPath(directory.path() + "/MyComponent.java")); RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); allowAnyoneOnProjects(project); @@ -286,9 +286,9 @@ public class SearchActionComponentsTest { @Test public void search_by_view_uuid() { - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); - ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setDbKey("MyView")); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1")); + ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setKey("MyView")); db.components().insertComponent(newProjectCopy(project, view)); RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); @@ -303,11 +303,11 @@ public class SearchActionComponentsTest { @Test public void search_by_sub_view_uuid() { - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1")); RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); - ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setDbKey("MyView")); + ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setKey("MyView")); ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SV1", "MySubView")); db.components().insertComponent(newProjectCopy(project, subView)); allowAnyoneOnProjects(project, view, subView); @@ -321,11 +321,11 @@ public class SearchActionComponentsTest { @Test public void search_by_sub_view_uuid_return_only_authorized_view() { - ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); + ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1")); RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); - ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setDbKey("MyView")); + ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setKey("MyView")); ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SV1", "MySubView")); db.components().insertComponent(newProjectCopy(project, subView)); // User has no permission on the view, no issue will be returned @@ -353,7 +353,7 @@ public class SearchActionComponentsTest { indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, application.getKey()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).extracting(Issue::getKey) @@ -362,14 +362,14 @@ public class SearchActionComponentsTest { @Test public void search_by_application_key_and_branch() { - ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setDbKey("app")); + ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app")); ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1")); ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2")); - ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("prj1")); + ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1")); ComponentDto project1Branch1 = db.components().insertProjectBranch(project1); ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1)); ComponentDto project1Branch2 = db.components().insertProjectBranch(project1); - ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("prj2")); + ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2")); db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1)); db.components().insertComponents(newProjectCopy(project2, applicationBranch1)); db.components().insertComponents(newProjectCopy(project1Branch2, applicationBranch2)); @@ -421,7 +421,7 @@ public class SearchActionComponentsTest { indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, application.getKey()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).isEmpty(); @@ -437,7 +437,7 @@ public class SearchActionComponentsTest { indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, application.getKey()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).isEmpty(); @@ -465,7 +465,7 @@ public class SearchActionComponentsTest { indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, application.getKey()) .setParam(PARAM_SINCE_LEAK_PERIOD, "true") .executeProtobuf(SearchWsResponse.class); @@ -488,8 +488,8 @@ public class SearchActionComponentsTest { indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) - .setParam(PARAM_PROJECTS, project1.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, application.getKey()) + .setParam(PARAM_PROJECTS, project1.getKey()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).extracting(Issue::getKey) @@ -519,8 +519,8 @@ public class SearchActionComponentsTest { indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) - .setParam(PARAM_PROJECTS, project1.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, application.getKey()) + .setParam(PARAM_PROJECTS, project1.getKey()) .setParam(PARAM_SINCE_LEAK_PERIOD, "true") .executeProtobuf(SearchWsResponse.class); @@ -551,7 +551,7 @@ public class SearchActionComponentsTest { indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, application.getKey()) .setParam(PARAM_SINCE_LEAK_PERIOD, "true") .executeProtobuf(SearchWsResponse.class); @@ -704,7 +704,7 @@ public class SearchActionComponentsTest { indexIssues(); SearchWsResponse result = ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, branch.getDbKey()) + .setParam(PARAM_COMPONENT_KEYS, branch.getKey()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).isEmpty(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index 9d195878e38..fd08abd57be 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -358,7 +358,7 @@ public class SearchActionTest { .setChangeData("*My comment*") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(john.getUuid()) - .setProjectUuid(project.projectUuid()) + .setProjectUuid(project.branchUuid()) .setIssueChangeCreationDate(parseDateTime("2014-09-09T12:00:00+0000").getTime())); dbClient.issueChangeDao().insert(session, new IssueChangeDto() @@ -368,7 +368,7 @@ public class SearchActionTest { .setChangeData("Another comment") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(fabrice.getUuid()) - .setProjectUuid(project.projectUuid()) + .setProjectUuid(project.branchUuid()) .setIssueChangeCreationDate(parseDateTime("2014-09-10T12:00:00+0000").getTime())); dbClient.issueChangeDao().insert(session, new IssueChangeDto() @@ -377,7 +377,7 @@ public class SearchActionTest { .setKey("COMMENT-NO-USER") .setChangeData("Another comment without user") .setChangeType(IssueChangeDto.TYPE_COMMENT) - .setProjectUuid(project.projectUuid()) + .setProjectUuid(project.branchUuid()) .setIssueChangeCreationDate(parseDateTime("2022-09-10T12:00:00+0000").getTime())); session.commit(); indexIssues(); @@ -406,7 +406,7 @@ public class SearchActionTest { .setChangeData("*My comment*") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(john.getUuid()) - .setProjectUuid(project.projectUuid()) + .setProjectUuid(project.branchUuid()) .setCreatedAt(parseDateTime("2014-09-09T12:00:00+0000").getTime())); dbClient.issueChangeDao().insert(session, new IssueChangeDto() @@ -416,7 +416,7 @@ public class SearchActionTest { .setChangeData("Another comment") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(fabrice.getUuid()) - .setProjectUuid(project.projectUuid()) + .setProjectUuid(project.branchUuid()) .setCreatedAt(parseDateTime("2014-09-10T19:10:03+0000").getTime())); session.commit(); indexIssues(); @@ -452,10 +452,10 @@ public class SearchActionTest { UserDto simon = db.users().insertUser(u -> u.setLogin("simon").setName("Simon").setEmail("simon@email.com")); UserDto fabrice = db.users().insertUser(u -> u.setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com")); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY").setLanguage("java")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java")); grantPermissionToAnyone(project, ISSUE_ADMIN); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY").setLanguage("js")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("js")); IssueDto issue = newDto(newIssueRule(), file, project) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") @@ -476,8 +476,8 @@ public class SearchActionTest { @Test public void search_by_rule_key() { RuleDto rule = newIssueRule(); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY").setLanguage("java")); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY").setLanguage("java")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("java")); db.issues().insertIssue(rule, project, file); session.commit(); @@ -497,8 +497,8 @@ public class SearchActionTest { @Test public void search_by_non_existing_rule_key() { RuleDto rule = newIssueRule(); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY").setLanguage("java")); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY").setLanguage("java")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("java")); db.issues().insertIssue(rule, project, file); session.commit(); @@ -518,10 +518,10 @@ public class SearchActionTest { @Test public void issue_on_removed_file() { RuleDto rule = newIssueRule(); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); ComponentDto removedFile = db.components().insertComponent(newFileDto(project, null).setUuid("REMOVED_FILE_ID") - .setDbKey("REMOVED_FILE_KEY") + .setKey("REMOVED_FILE_KEY") .setEnabled(false)); IssueDto issue = newDto(rule, removedFile, project) @@ -543,9 +543,9 @@ public class SearchActionTest { @Test public void apply_paging_with_one_component() { RuleDto rule = newIssueRule(); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); for (int i = 0; i < SearchOptions.MAX_PAGE_SIZE + 1; i++) { IssueDto issue = newDto(rule, file, project).setAssigneeUuid(null); dbClient.issueDao().insert(session, issue); @@ -559,10 +559,10 @@ public class SearchActionTest { @Test public void components_contains_sub_projects() { - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("ProjectHavingModule")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("ProjectHavingModule")); indexPermissions(); - ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setDbKey("ModuleHavingFile")); - ComponentDto file = db.components().insertComponent(newFileDto(module, null, "BCDE").setDbKey("FileLinkedToModule")); + ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setKey("ModuleHavingFile")); + ComponentDto file = db.components().insertComponent(newFileDto(module, null, "BCDE").setKey("FileLinkedToModule")); IssueDto issue = newDto(newIssueRule(), file, project); dbClient.issueDao().insert(session, issue); session.commit(); @@ -576,9 +576,9 @@ public class SearchActionTest { public void filter_by_assigned_to_me() { UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com")); UserDto alice = db.users().insertUser(u -> u.setLogin("alice").setName("Alice").setEmail("alice@email.com")); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, file, project) .setIssueCreationDate(parseDate("2014-09-04")) @@ -622,11 +622,11 @@ public class SearchActionTest { public void filter_by_new_code_period() { UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com")); UserDto alice = db.users().insertUser(u -> u.setLogin("alice").setName("Alice").setEmail("alice@email.com")); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); SnapshotDto snapshotDto = db.components().insertSnapshot(project, s -> s.setLast(true).setPeriodDate(parseDateTime("2014-09-05T00:00:00+0100").getTime())); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, file, project) .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) @@ -693,10 +693,10 @@ public class SearchActionTest { public void filter_by_leak_period_without_a_period() { UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com")); UserDto alice = db.users().insertUser(u -> u.setLogin("alice").setName("Alice").setEmail("alice@email.com")); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); SnapshotDto snapshotDto = db.components().insertSnapshot(project); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, file, project) .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) @@ -744,11 +744,11 @@ public class SearchActionTest { public void filter_by_leak_period_has_no_effect_on_prs() { UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com")); UserDto alice = db.users().insertUser(u -> u.setLogin("alice").setName("Alice").setEmail("alice@email.com")); - ComponentDto project = db.components().insertPublicProject(c -> c.setUuid("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertPublicProject(c -> c.setUuid("PROJECT_ID").setKey("PROJECT_KEY")); ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey("pr")); SnapshotDto snapshotDto = db.components().insertSnapshot(pr); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(pr, null, "FILE_ID").setDbKey("FILE_KEY" + PULL_REQUEST_SEPARATOR + "pr")); + ComponentDto file = db.components().insertComponent(newFileDto(pr, null, "FILE_ID").setKey("FILE_KEY" + PULL_REQUEST_SEPARATOR + "pr")); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, file, pr) .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) @@ -799,9 +799,9 @@ public class SearchActionTest { public void return_empty_when_login_is_unknown() { UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com")); UserDto alice = db.users().insertUser(u -> u.setLogin("alice").setName("Alice").setEmail("alice@email.com")); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, file, project) .setIssueCreationDate(parseDate("2014-09-04")) @@ -848,9 +848,9 @@ public class SearchActionTest { userSession.logIn(poy); UserDto alice = db.users().insertUser(u -> u.setLogin("alice").setName("Alice").setEmail("alice@email.com")); UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com")); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, file, project) .setStatus("OPEN") @@ -909,12 +909,12 @@ public class SearchActionTest { @Test public void filter_by_test_scope() { - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); ComponentDto mainCodeFile = db.components().insertComponent( - newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); ComponentDto testCodeFile = db.components().insertComponent( - newFileDto(project, null, "ANOTHER_FILE_ID").setDbKey("ANOTHER_FILE_KEY").setQualifier(UNIT_TEST_FILE)); + newFileDto(project, null, "ANOTHER_FILE_ID").setKey("ANOTHER_FILE_KEY").setQualifier(UNIT_TEST_FILE)); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, mainCodeFile, project) .setIssueCreationDate(parseDate("2014-09-04")) @@ -950,12 +950,12 @@ public class SearchActionTest { @Test public void filter_by_main_scope() { - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); ComponentDto mainCodeFile = db.components().insertComponent( - newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); ComponentDto testCodeFile = db.components().insertComponent( - newFileDto(project, null, "ANOTHER_FILE_ID").setDbKey("ANOTHER_FILE_KEY").setQualifier(UNIT_TEST_FILE)); + newFileDto(project, null, "ANOTHER_FILE_ID").setKey("ANOTHER_FILE_KEY").setQualifier(UNIT_TEST_FILE)); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, mainCodeFile, project) .setType(CODE_SMELL) @@ -994,10 +994,10 @@ public class SearchActionTest { @Test public void filter_by_scope_always_returns_all_scope_facet_values() { - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); ComponentDto mainCodeFile = db.components().insertComponent( - newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, mainCodeFile, project) .setType(CODE_SMELL) @@ -1029,9 +1029,9 @@ public class SearchActionTest { @Test public void sort_by_updated_at() { RuleDto rule = newIssueRule(); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); dbClient.issueDao().insert(session, newDto(rule, file, project) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac1") .setIssueUpdateDate(parseDateTime("2014-11-02T00:00:00+0100"))); @@ -1694,9 +1694,9 @@ public class SearchActionTest { @Test public void paging() { RuleDto rule = newIssueRule(); - ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); + ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); for (int i = 0; i < 12; i++) { IssueDto issue = newDto(rule, file, project); dbClient.issueDao().insert(session, issue); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchResponseFormatFormatOperationTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchResponseFormatFormatOperationTest.java index c5f5878b552..6b98e7d82d8 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchResponseFormatFormatOperationTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchResponseFormatFormatOperationTest.java @@ -161,13 +161,13 @@ public class SearchResponseFormatFormatOperationTest { RuleDto ruleDto = newRule(); String projectUuid = "project_uuid_" + randomAlphanumeric(5); ComponentDto projectDto = newPrivateProjectDto(); - projectDto.setProjectUuid(projectUuid); + projectDto.setBranchUuid(projectUuid); return newIssue(ruleDto, projectUuid, "project_key_" + randomAlphanumeric(5), projectDto); } @Test public void formatOperation_should_add_branch_on_issue() { - componentDto.setDbKey(randomAlphanumeric(5) + BRANCH_KEY_SEPARATOR + randomAlphanumeric(5)); + componentDto.setKey(randomAlphanumeric(5) + BRANCH_KEY_SEPARATOR + randomAlphanumeric(5)); Operation result = searchResponseFormat.formatOperation(searchResponseData); @@ -176,7 +176,7 @@ public class SearchResponseFormatFormatOperationTest { @Test public void formatOperation_should_add_pullrequest_on_issue() { - componentDto.setDbKey(randomAlphanumeric(5) + PULL_REQUEST_SEPARATOR + randomAlphanumeric(5)); + componentDto.setKey(randomAlphanumeric(5) + PULL_REQUEST_SEPARATOR + randomAlphanumeric(5)); Operation result = searchResponseFormat.formatOperation(searchResponseData); @@ -283,7 +283,7 @@ public class SearchResponseFormatFormatOperationTest { String projectUuid = "project_uuid_" + randomAlphanumeric(5); ComponentDto projectDto = newPrivateProjectDto(); - projectDto.setProjectUuid(projectUuid); + projectDto.setBranchUuid(projectUuid); UserDto userDto = newUserDto(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java index c7d69683615..9900dcf7bc2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java @@ -95,7 +95,7 @@ public class ComponentActionTest { assertThat(response.getMetrics().getMetricsCount()).isOne(); assertThat(response.hasPeriod()).isFalse(); assertThat(response.getPeriods().getPeriodsCount()).isZero(); - assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); + assertThat(response.getComponent().getKey()).isEqualTo(project.getKey()); } @Test @@ -243,11 +243,11 @@ public class ComponentActionTest { MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); ComponentWsResponse response = ws.newRequest() - .setParam("component", project.getDbKey()) + .setParam("component", project.getKey()) .setParam(PARAM_METRIC_KEYS, metric.getKey()) .executeProtobuf(ComponentWsResponse.class); - assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); + assertThat(response.getComponent().getKey()).isEqualTo(project.getKey()); } @Test @@ -386,12 +386,12 @@ public class ComponentActionTest { assertThatThrownBy(() -> { ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getDbKey()) + .setParam(PARAM_COMPONENT, branch.getKey()) .setParam(PARAM_METRIC_KEYS, metric.getKey()) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } @Test @@ -403,7 +403,7 @@ public class ComponentActionTest { .setPeriodMode("previous_version") .setPeriodParam("1.0-SNAPSHOT")); ComponentDto file = db.components().insertComponent(newFileDto(project) - .setDbKey("MY_PROJECT:ElementImpl.java") + .setKey("MY_PROJECT:ElementImpl.java") .setName("ElementImpl.java") .setLanguage("java") .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index 70aa1394b4e..0afae7b792c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -116,7 +116,7 @@ public class ComponentTreeActionTest { @Test public void json_example() { - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT") + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("MY_PROJECT") .setName("My Project")); userSession.addProjectPermission(USER, project); SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()) @@ -124,21 +124,21 @@ public class ComponentTreeActionTest { .setPeriodParam("1.0-SNAPSHOT")); ComponentDto file1 = db.components().insertComponent(newFileDto(project, null) .setUuid("AVIwDXE-bJbJqrw6wFv5") - .setDbKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java") + .setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java") .setName("ElementImpl.java") .setLanguage("java") .setQualifier(FILE) .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java")); ComponentDto file2 = db.components().insertComponent(newFileDto(project, null) .setUuid("AVIwDXE_bJbJqrw6wFwJ") - .setDbKey("com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java") + .setKey("com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java") .setName("ElementImplTest.java") .setLanguage("java") .setQualifier(UNIT_TEST_FILE) .setPath("src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java")); ComponentDto dir = db.components().insertComponent(newDirectory(project, "src/main/java/com/sonarsource/markdown/impl") .setUuid("AVIwDXE-bJbJqrw6wFv8") - .setDbKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl") + .setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl") .setQualifier(DIRECTORY)); MetricDto complexity = insertComplexityMetric(); @@ -353,15 +353,15 @@ public class ComponentTreeActionTest { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(USER, project); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file9 = db.components().insertComponent(newFileDto(project, null, "file-uuid-9").setName("file-1").setDbKey("file-9-key")); - ComponentDto file8 = db.components().insertComponent(newFileDto(project, null, "file-uuid-8").setName("file-1").setDbKey("file-8-key")); - ComponentDto file7 = db.components().insertComponent(newFileDto(project, null, "file-uuid-7").setName("file-1").setDbKey("file-7-key")); - ComponentDto file6 = db.components().insertComponent(newFileDto(project, null, "file-uuid-6").setName("file-1").setDbKey("file-6-key")); - ComponentDto file5 = db.components().insertComponent(newFileDto(project, null, "file-uuid-5").setName("file-1").setDbKey("file-5-key")); - ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setName("file-1").setDbKey("file-4-key")); - ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setName("file-1").setDbKey("file-3-key")); - ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setName("file-1").setDbKey("file-2-key")); - ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setName("file-1").setDbKey("file-1-key")); + ComponentDto file9 = db.components().insertComponent(newFileDto(project, null, "file-uuid-9").setName("file-1").setKey("file-9-key")); + ComponentDto file8 = db.components().insertComponent(newFileDto(project, null, "file-uuid-8").setName("file-1").setKey("file-8-key")); + ComponentDto file7 = db.components().insertComponent(newFileDto(project, null, "file-uuid-7").setName("file-1").setKey("file-7-key")); + ComponentDto file6 = db.components().insertComponent(newFileDto(project, null, "file-uuid-6").setName("file-1").setKey("file-6-key")); + ComponentDto file5 = db.components().insertComponent(newFileDto(project, null, "file-uuid-5").setName("file-1").setKey("file-5-key")); + ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setName("file-1").setKey("file-4-key")); + ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setName("file-1").setKey("file-3-key")); + ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setName("file-1").setKey("file-2-key")); + ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setName("file-1").setKey("file-1-key")); MetricDto coverage = insertCoverageMetric(); db.commit(); db.measures().insertLiveMeasure(file1, coverage, m -> m.setValue(1.0d)); @@ -396,10 +396,10 @@ public class ComponentTreeActionTest { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(USER, project); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setDbKey("file-4-key")); - ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key")); - ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key")); - ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key")); + ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setKey("file-4-key")); + ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setKey("file-3-key")); + ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setKey("file-1-key")); + ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setKey("file-2-key")); MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); db.commit(); @@ -423,10 +423,10 @@ public class ComponentTreeActionTest { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(USER, project); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file1 = newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key"); - ComponentDto file2 = newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key"); - ComponentDto file3 = newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key"); - ComponentDto file4 = newFileDto(project, null, "file-uuid-4").setDbKey("file-4-key"); + ComponentDto file1 = newFileDto(project, null, "file-uuid-1").setKey("file-1-key"); + ComponentDto file2 = newFileDto(project, null, "file-uuid-2").setKey("file-2-key"); + ComponentDto file3 = newFileDto(project, null, "file-uuid-3").setKey("file-3-key"); + ComponentDto file4 = newFileDto(project, null, "file-uuid-4").setKey("file-4-key"); db.components().insertComponent(file1); db.components().insertComponent(file2); db.components().insertComponent(file3); @@ -459,9 +459,9 @@ public class ComponentTreeActionTest { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(USER, project); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key")); - ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key")); - ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key")); + ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setKey("file-3-key")); + ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setKey("file-1-key")); + ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setKey("file-2-key")); MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); db.commit(); @@ -485,10 +485,10 @@ public class ComponentTreeActionTest { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(USER, project); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setDbKey("file-4-key")); - ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key")); - ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key")); - ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key")); + ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setKey("file-4-key")); + ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setKey("file-3-key")); + ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setKey("file-2-key")); + ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setKey("file-1-key")); MetricDto ncloc = newMetricDto().setKey("new_ncloc").setValueType(INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(null).setVariation(1.0d)); @@ -674,7 +674,7 @@ public class ComponentTreeActionTest { @Test public void portfolio_local_reference_in_portfolio() { ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("VIEW1-UUID") - .setDbKey("Apache-Projects").setName("Apache Projects")); + .setKey("Apache-Projects").setName("Apache Projects")); userSession.registerComponents(view); ComponentDto view2 = db.components().insertPrivatePortfolio(); userSession.addProjectPermission(USER, view2); @@ -697,7 +697,7 @@ public class ComponentTreeActionTest { @Test public void application_local_reference_in_portfolio() { ComponentDto apache_projects = ComponentTesting.newPortfolio("VIEW1-UUID") - .setDbKey("Apache-Projects").setName("Apache Projects").setPrivate(true); + .setKey("Apache-Projects").setName("Apache Projects").setPrivate(true); userSession.addProjectPermission(USER, apache_projects); ComponentDto view = db.components().insertComponent(apache_projects); ComponentDto application = db.components().insertPrivateApplication(); @@ -721,13 +721,13 @@ public class ComponentTreeActionTest { @Test public void project_branch_reference_from_application_branch() { MetricDto ncloc = insertNclocMetric(); - ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setDbKey("app-key")); + ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app-key")); userSession.registerApplication(application); ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey("app-branch"), a -> a.setUuid("custom-uuid")); - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("project-key")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key")); ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch")); ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch) - .setDbKey(applicationBranch.getKey() + applicationBranch.getBranch() + projectBranch.getDbKey())); + .setKey(applicationBranch.getKey() + applicationBranch.getBranch() + projectBranch.getKey())); SnapshotDto applicationBranchAnalysis = db.components().insertSnapshot(applicationBranch); db.measures().insertLiveMeasure(applicationBranch, ncloc, m -> m.setValue(5d)); db.measures().insertLiveMeasure(techProjectBranch, ncloc, m -> m.setValue(1d)); @@ -993,7 +993,7 @@ public class ComponentTreeActionTest { public void fail_when_component_is_removed() { ComponentDto project = db.components().insertPrivateProject(); db.components().insertSnapshot(project); - ComponentDto file = db.components().insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false)); + ComponentDto file = db.components().insertComponent(newFileDto(project).setKey("file-key").setEnabled(false)); userSession.anonymous().addProjectPermission(USER, project); insertNclocMetric(); @@ -1034,12 +1034,12 @@ public class ComponentTreeActionTest { assertThatThrownBy(() -> { ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getDbKey()) + .setParam(PARAM_COMPONENT, branch.getKey()) .setParam(PARAM_METRIC_KEYS, "ncloc") .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } private static MetricDto newMetricDto() { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java index 9ed94cbaeba..daeeaee2439 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java @@ -70,9 +70,9 @@ public class SearchActionTest { @Test public void json_example() { - ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT_1").setName("Project 1")); - ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT_2").setName("Project 2")); - ComponentDto project3 = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT_3").setName("Project 3")); + ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("MY_PROJECT_1").setName("Project 1")); + ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("MY_PROJECT_2").setName("Project 2")); + ComponentDto project3 = db.components().insertPrivateProject(p -> p.setKey("MY_PROJECT_3").setName("Project 3")); userSession.addProjectPermission(UserRole.USER, project1); userSession.addProjectPermission(UserRole.USER, project2); @@ -93,7 +93,7 @@ public class SearchActionTest { db.measures().insertLiveMeasure(project2, newViolations, m -> m.setVariation(25.0d)); db.measures().insertLiveMeasure(project3, newViolations, m -> m.setVariation(255.0d)); - List<String> projectKeys = Arrays.asList(project1.getDbKey(), project2.getDbKey(), project3.getDbKey()); + List<String> projectKeys = Arrays.asList(project1.getKey(), project2.getKey(), project3.getKey()); String result = ws.newRequest() .setParam(PARAM_PROJECT_KEYS, Joiner.on(",").join(projectKeys)) @@ -111,7 +111,7 @@ public class SearchActionTest { MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d)); - SearchWsResponse result = call(singletonList(project.getDbKey()), singletonList(coverage.getKey())); + SearchWsResponse result = call(singletonList(project.getKey()), singletonList(coverage.getKey())); List<Measure> measures = result.getMeasuresList(); assertThat(measures).hasSize(1); @@ -131,7 +131,7 @@ public class SearchActionTest { MetricDto noBestValue = db.measures().insertMetric(m -> m.setValueType(INT.name()).setBestValue(null)); db.measures().insertLiveMeasure(project, noBestValue, m -> m.setValue(123d)); - SearchWsResponse result = call(singletonList(project.getDbKey()), + SearchWsResponse result = call(singletonList(project.getKey()), asList(matchBestValue.getKey(), doesNotMatchBestValue.getKey(), noBestValue.getKey())); List<Measure> measures = result.getMeasuresList(); @@ -150,7 +150,7 @@ public class SearchActionTest { MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d).setVariation(10d)); - SearchWsResponse result = call(singletonList(project.getDbKey()), singletonList(coverage.getKey())); + SearchWsResponse result = call(singletonList(project.getKey()), singletonList(coverage.getKey())); List<Measure> measures = result.getMeasuresList(); assertThat(measures).hasSize(1); @@ -179,12 +179,12 @@ public class SearchActionTest { db.measures().insertLiveMeasure(project2, complexity, m -> m.setValue(15d)); db.measures().insertLiveMeasure(project3, complexity, m -> m.setValue(20d)); - SearchWsResponse result = call(asList(project1.getDbKey(), project2.getDbKey(), project3.getDbKey()), asList(coverage.getKey(), complexity.getKey())); + SearchWsResponse result = call(asList(project1.getKey(), project2.getKey(), project3.getKey()), asList(coverage.getKey(), complexity.getKey())); assertThat(result.getMeasuresList()).extracting(Measure::getMetric, Measure::getComponent) .containsExactly( - tuple(complexity.getKey(), project2.getDbKey()), tuple(complexity.getKey(), project3.getDbKey()), tuple(complexity.getKey(), project1.getDbKey()), - tuple(coverage.getKey(), project2.getDbKey()), tuple(coverage.getKey(), project3.getDbKey()), tuple(coverage.getKey(), project1.getDbKey())); + tuple(complexity.getKey(), project2.getKey()), tuple(complexity.getKey(), project3.getKey()), tuple(complexity.getKey(), project1.getKey()), + tuple(coverage.getKey(), project2.getKey()), tuple(coverage.getKey(), project3.getKey()), tuple(coverage.getKey(), project1.getKey())); } @Test @@ -194,7 +194,7 @@ public class SearchActionTest { MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); db.measures().insertLiveMeasure(view, coverage, m -> m.setValue(15.5d)); - SearchWsResponse result = call(singletonList(view.getDbKey()), singletonList(coverage.getKey())); + SearchWsResponse result = call(singletonList(view.getKey()), singletonList(coverage.getKey())); List<Measure> measures = result.getMeasuresList(); assertThat(measures).hasSize(1); @@ -210,7 +210,7 @@ public class SearchActionTest { MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); db.measures().insertLiveMeasure(application, coverage, m -> m.setValue(15.5d)); - SearchWsResponse result = call(singletonList(application.getDbKey()), singletonList(coverage.getKey())); + SearchWsResponse result = call(singletonList(application.getKey()), singletonList(coverage.getKey())); List<Measure> measures = result.getMeasuresList(); assertThat(measures).hasSize(1); @@ -227,7 +227,7 @@ public class SearchActionTest { MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); db.measures().insertLiveMeasure(subView, metric, m -> m.setValue(15.5d)); - SearchWsResponse result = call(singletonList(subView.getDbKey()), singletonList(metric.getKey())); + SearchWsResponse result = call(singletonList(subView.getKey()), singletonList(metric.getKey())); List<Measure> measures = result.getMeasuresList(); assertThat(measures).hasSize(1); @@ -245,9 +245,9 @@ public class SearchActionTest { db.measures().insertLiveMeasure(project2, metric, m -> m.setValue(42.0d)); Arrays.stream(new ComponentDto[] {project1}).forEach(p -> userSession.addProjectPermission(UserRole.USER, p)); - SearchWsResponse result = call(asList(project1.getDbKey(), project2.getDbKey()), singletonList(metric.getKey())); + SearchWsResponse result = call(asList(project1.getKey(), project2.getKey()), singletonList(metric.getKey())); - assertThat(result.getMeasuresList()).extracting(Measure::getComponent).containsOnly(project1.getDbKey()); + assertThat(result.getMeasuresList()).extracting(Measure::getComponent).containsOnly(project1.getKey()); } @Test @@ -258,7 +258,7 @@ public class SearchActionTest { db.measures().insertLiveMeasure(branch, coverage, m -> m.setValue(10d)); userSession.addProjectPermission(UserRole.USER, project); - SearchWsResponse result = call(singletonList(branch.getDbKey()), singletonList(coverage.getKey())); + SearchWsResponse result = call(singletonList(branch.getKey()), singletonList(coverage.getKey())); assertThat(result.getMeasuresList()).isEmpty(); } @@ -289,7 +289,7 @@ public class SearchActionTest { userSession.addProjectPermission(UserRole.USER, project); MetricDto metric = db.measures().insertMetric(); - assertThatThrownBy(() -> call(singletonList(project.getDbKey()), newArrayList("violations", metric.getKey(), "ncloc"))) + assertThatThrownBy(() -> call(singletonList(project.getKey()), newArrayList("violations", metric.getKey(), "ncloc"))) .isInstanceOf(BadRequestException.class) .hasMessage("The following metrics are not found: ncloc, violations"); } @@ -316,7 +316,7 @@ public class SearchActionTest { public void fail_if_more_than_100_project_keys() { List<String> keys = IntStream.rangeClosed(1, 101) .mapToObj(i -> db.components().insertPrivateProject()) - .map(ComponentDto::getDbKey) + .map(ComponentDto::getKey) .collect(Collectors.toList()); MetricDto metric = db.measures().insertMetric(); @@ -329,7 +329,7 @@ public class SearchActionTest { public void does_not_fail_on_100_projects() { List<String> keys = IntStream.rangeClosed(1, 100) .mapToObj(i -> db.components().insertPrivateProject()) - .map(ComponentDto::getDbKey) + .map(ComponentDto::getKey) .collect(Collectors.toList()); MetricDto metric = db.measures().insertMetric(); @@ -343,7 +343,7 @@ public class SearchActionTest { userSession.addProjectPermission(UserRole.USER, project); MetricDto metric = db.measures().insertMetric(); - assertThatThrownBy(() -> call(singletonList(module.getDbKey()), singletonList(metric.getKey()))) + assertThatThrownBy(() -> call(singletonList(module.getKey()), singletonList(metric.getKey()))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Only component of qualifiers [TRK, APP, VW, SVW] are allowed"); } @@ -355,7 +355,7 @@ public class SearchActionTest { userSession.addProjectPermission(UserRole.USER, project); MetricDto metric = db.measures().insertMetric(); - assertThatThrownBy(() -> call(singletonList(dir.getDbKey()), singletonList(metric.getKey()))) + assertThatThrownBy(() -> call(singletonList(dir.getKey()), singletonList(metric.getKey()))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Only component of qualifiers [TRK, APP, VW, SVW] are allowed"); } @@ -367,7 +367,7 @@ public class SearchActionTest { userSession.addProjectPermission(UserRole.USER, project); MetricDto metric = db.measures().insertMetric(); - assertThatThrownBy(() -> call(singletonList(file.getDbKey()), singletonList(metric.getKey()))) + assertThatThrownBy(() -> call(singletonList(file.getKey()), singletonList(metric.getKey()))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Only component of qualifiers [TRK, APP, VW, SVW] are allowed"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java index 73d9054b9e8..3d17e12fe0c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java @@ -110,7 +110,7 @@ public class SearchHistoryActionTest { project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(singletonList(complexityMetric.getKey())) .build(); @@ -131,7 +131,7 @@ public class SearchHistoryActionTest { userSession.addProjectPermission(UserRole.USER, project); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(singletonList(complexityMetric.getKey())) .build(); @@ -148,7 +148,7 @@ public class SearchHistoryActionTest { db.commit(); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())) .build(); @@ -173,7 +173,7 @@ public class SearchHistoryActionTest { db.commit(); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())) .build(); SearchHistoryResponse result = call(request); @@ -213,7 +213,7 @@ public class SearchHistoryActionTest { db.commit(); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())) .setPage(2) .setPageSize(3) @@ -237,7 +237,7 @@ public class SearchHistoryActionTest { db.commit(); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())) .setFrom(analysisDates.get(1)) .setTo(analysisDates.get(3)) @@ -257,7 +257,7 @@ public class SearchHistoryActionTest { ComponentDto file = db.components().insertComponent(newFileDto(project)); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(file.getDbKey()) + .setComponent(file.getKey()) .setMetrics(asList("optimized", "new_optimized")) .build(); SearchHistoryResponse result = call(request); @@ -268,7 +268,7 @@ public class SearchHistoryActionTest { // Best value is not applied to project request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(asList("optimized", "new_optimized")) .build(); result = call(request); @@ -283,7 +283,7 @@ public class SearchHistoryActionTest { db.commit(); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())) .build(); SearchHistoryResponse result = call(request); @@ -345,17 +345,17 @@ public class SearchHistoryActionTest { ComponentDto branch = db.components().insertProjectBranch(project); assertThatThrownBy(() -> ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getDbKey()) + .setParam(PARAM_COMPONENT, branch.getKey()) .setParam(PARAM_METRICS, "ncloc") .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); } @Test public void fail_if_unknown_metric() { SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), "METRIC_42", "42_METRIC")) .build(); @@ -368,7 +368,7 @@ public class SearchHistoryActionTest { public void fail_if_not_enough_permissions() { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(singletonList(complexityMetric.getKey())) .build(); @@ -390,7 +390,7 @@ public class SearchHistoryActionTest { .addProjectPermission(UserRole.USER, application, project1); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(application.getDbKey()) + .setComponent(application.getKey()) .setMetrics(singletonList(complexityMetric.getKey())) .build(); @@ -412,7 +412,7 @@ public class SearchHistoryActionTest { @Test public void fail_when_component_is_removed() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto()); - db.components().insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false)); + db.components().insertComponent(newFileDto(project).setKey("file-key").setEnabled(false)); userSession.addProjectPermission(UserRole.USER, project); assertThatThrownBy(() -> ws.newRequest() @@ -470,7 +470,7 @@ public class SearchHistoryActionTest { db.commit(); String result = ws.newRequest() - .setParam(PARAM_COMPONENT, project.getDbKey()) + .setParam(PARAM_COMPONENT, project.getKey()) .setParam(PARAM_METRICS, String.join(",", asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey()))) .execute().getInput(); @@ -483,7 +483,7 @@ public class SearchHistoryActionTest { db.commit(); SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(project.getDbKey()) + .setComponent(project.getKey()) .setMetrics(singletonList(stringMetric.getKey())) .build(); SearchHistoryResponse result = call(request); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ShowActionTest.java index 98a5b3aed7d..2ae9fdf54d1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ShowActionTest.java @@ -218,7 +218,7 @@ public class ShowActionTest { ComponentDto project = componentDb.insertPublicProject(); logInAsProjectScan(project); - tester.insert(project.projectUuid(), NewCodePeriodType.NUMBER_OF_DAYS, "3"); + tester.insert(project.branchUuid(), NewCodePeriodType.NUMBER_OF_DAYS, "3"); ShowWSResponse response = ws.newRequest() .setParam("project", project.getKey()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java index 6008edc1024..36d5097c81d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java @@ -110,7 +110,7 @@ public class AddActionTest { when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); + call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), null); db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), project); } @@ -124,7 +124,7 @@ public class AddActionTest { when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); + call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), null); db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), project); } @@ -137,7 +137,7 @@ public class AddActionTest { when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES)); ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(USER, project); - call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); + call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), null); call(NOTIF_MY_NEW_ISSUES, null, null, null); @@ -155,7 +155,7 @@ public class AddActionTest { call(NOTIF_MY_NEW_ISSUES, null, null, null); userSession.addProjectPermission(USER, project); - call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); + call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), null); db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), project); db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), null); @@ -171,7 +171,7 @@ public class AddActionTest { userSession.registerComponents(project); call(NOTIF_MY_NEW_ISSUES, null, null, null); - call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); + call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), null); db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), project); db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), null); @@ -295,7 +295,7 @@ public class AddActionTest { public void fail_when_component_is_not_a_project() { UserDto user = db.users().insertUser(); userSession.logIn(user); - db.components().insertPortfolioAndSnapshot(newPortfolio().setDbKey("VIEW_1")); + db.components().insertPortfolioAndSnapshot(newPortfolio().setKey("VIEW_1")); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); @@ -321,9 +321,9 @@ public class AddActionTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto branch = db.components().insertProjectBranch(project); - assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, branch.getDbKey(), null)) + assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, branch.getKey(), null)) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); } @Test @@ -333,7 +333,7 @@ public class AddActionTest { when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), userSession.getLogin())) + assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), userSession.getLogin())) .isInstanceOf(ForbiddenException.class); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/ListActionTest.java index b465137c56d..5cbf00521a2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/ListActionTest.java @@ -241,7 +241,7 @@ public class ListActionTest { userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS)); when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS)); - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey(KEY_PROJECT_EXAMPLE_001).setName("My Project")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey(KEY_PROJECT_EXAMPLE_001).setName("My Project")); db.users().insertProjectPermissionOnUser(user, USER, project); notificationUpdater.add(dbSession, twitterChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null); notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java index 97e4aa3d884..a72bfe25c13 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java @@ -116,7 +116,7 @@ public class RemoveActionTest { notificationUpdater.add(dbSession, defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, project); dbSession.commit(); - call(request.setProject(project.getDbKey())); + call(request.setProject(project.getKey())); db.notifications().assertDoesNotExist(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getUuid(), project); } @@ -146,7 +146,7 @@ public class RemoveActionTest { notificationUpdater.add(dbSession, defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null); dbSession.commit(); - RemoveRequest request = this.request.setProject(project.getDbKey()); + RemoveRequest request = this.request.setProject(project.getKey()); assertThatThrownBy(() -> call(request)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Notification doesn't exist"); @@ -248,7 +248,7 @@ public class RemoveActionTest { when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS)); ComponentDto project = db.components().insertPrivateProject(); - RemoveRequest request = this.request.setType("Dispatcher42").setProject(project.getDbKey()); + RemoveRequest request = this.request.setType("Dispatcher42").setProject(project.getKey()); assertThatThrownBy(() -> call(request)) .isInstanceOf(BadRequestException.class) .hasMessage("Value of parameter 'type' (Dispatcher42) must be one of: [Dispatcher1, Dispatcher3]"); @@ -284,7 +284,7 @@ public class RemoveActionTest { userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - db.components().insertPortfolioAndSnapshot(newPortfolio().setDbKey("VIEW_1")); + db.components().insertPortfolioAndSnapshot(newPortfolio().setKey("VIEW_1")); RemoveRequest request = this.request.setProject("VIEW_1"); assertThatThrownBy(() -> call(request)) @@ -310,10 +310,10 @@ public class RemoveActionTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto branch = db.components().insertProjectBranch(project); - RemoveRequest request = this.request.setProject(branch.getDbKey()); + RemoveRequest request = this.request.setProject(branch.getKey()); assertThatThrownBy(() -> call(request)) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } private TestResponse call(RemoveRequest remove) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java index 5d687921ea3..4119edf475a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java @@ -470,7 +470,7 @@ public class PermissionTemplateServiceTest { .map(x -> String.format("\"%s\"", x)) .collect(Collectors.joining(", ")); - ComponentDto project = dbTester.components().insertPrivateProject(p -> p.setDbKey(key)); + ComponentDto project = dbTester.components().insertPrivateProject(p -> p.setKey(key)); assertThatThrownBy(() -> underTest.applyDefaultToNewComponent(session, project, null)) .isInstanceOf(TemplateMatchingKeyException.class) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java index 69ca9cf2729..90f0663cd23 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java @@ -126,7 +126,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { @Test public void add_permission_to_project_referenced_by_its_id() { GroupDto group = db.users().insertGroup("sonar-administrators"); - ComponentDto project = db.components().insertComponent(newPrivateProjectDto(A_PROJECT_UUID).setDbKey(A_PROJECT_KEY)); + ComponentDto project = db.components().insertComponent(newPrivateProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY)); loginAsAdmin(); newRequest() @@ -142,7 +142,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { @Test public void add_permission_to_project_referenced_by_its_key() { GroupDto group = db.users().insertGroup("sonar-administrators"); - ComponentDto project = db.components().insertComponent(newPrivateProjectDto(A_PROJECT_UUID).setDbKey(A_PROJECT_KEY)); + ComponentDto project = db.components().insertComponent(newPrivateProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY)); loginAsAdmin(); newRequest() @@ -230,7 +230,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { .execute(); }) .isInstanceOf(BadRequestException.class) - .hasMessage("Component '" + file.getDbKey() + "' (id: " + file.uuid() + ") must be a project or a view."); + .hasMessage("Component '" + file.getKey() + "' (id: " + file.uuid() + ") must be a project or a view."); } @Test @@ -325,7 +325,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .setParam(PARAM_PROJECT_ID, project.uuid()) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute(); }) .isInstanceOf(BadRequestException.class) @@ -356,7 +356,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey()) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute(); }) .isInstanceOf(ForbiddenException.class); @@ -467,13 +467,13 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { assertThatThrownBy(() -> { newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getDbKey()) + .setParam(PARAM_PROJECT_KEY, branch.getKey()) .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PERMISSION, ISSUE_ADMIN) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getDbKey())); + .hasMessage(format("Project key '%s' not found", branch.getKey())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java index 237a70d74fe..e0d541afbe4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java @@ -106,7 +106,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> { newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); @@ -116,7 +116,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> { @Test public void add_permission_to_view() { - ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("view-uuid").setDbKey("view-key")); + ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("view-uuid").setKey("view-key")); loginAsAdmin(); newRequest() @@ -186,7 +186,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> { .execute(); }) .isInstanceOf(BadRequestException.class) - .hasMessage("Component '" + file.getDbKey() + "' (id: " + file.uuid() + ") must be a project or a view."); + .hasMessage("Component '" + file.getKey() + "' (id: " + file.uuid() + ") must be a project or a view."); } @Test @@ -295,7 +295,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> { newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute(); }) .isInstanceOf(ForbiddenException.class); @@ -312,7 +312,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> { newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .setParam(PARAM_PERMISSION, UserRole.ISSUE_ADMIN) .execute(); @@ -355,13 +355,13 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> { assertThatThrownBy(() -> { newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getDbKey()) + .setParam(PARAM_PROJECT_KEY, branch.getKey()) .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getDbKey())); + .hasMessage(format("Project key '%s' not found", branch.getKey())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java index c1d54a5e01b..d3dc23d714b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java @@ -257,7 +257,7 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> { @Test public void search_groups_on_views() { - ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("view-uuid").setDbKey("view-key")); + ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("view-uuid").setKey("view-key")); GroupDto group = db.users().insertGroup("project-group-name"); db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, view); @@ -341,11 +341,11 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> { assertThatThrownBy(() -> { newRequest() .setParam(PARAM_PERMISSION, ISSUE_ADMIN) - .setParam(PARAM_PROJECT_KEY, branch.getDbKey()) + .setParam(PARAM_PROJECT_KEY, branch.getKey()) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getDbKey())); + .hasMessage(format("Project key '%s' not found", branch.getKey())); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java index 48d8170b9ef..8ffaf36bcfd 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java @@ -161,7 +161,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio newRequest() .setParam(PARAM_GROUP_NAME, aGroup.getName()) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .setParam(PARAM_PERMISSION, ADMIN) .execute(); @@ -249,7 +249,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio .execute(); }) .isInstanceOf(BadRequestException.class) - .hasMessage("Component '" + file.getDbKey() + "' (id: " + file.uuid() + ") must be a project or a view."); + .hasMessage("Component '" + file.getKey() + "' (id: " + file.uuid() + ") must be a project or a view."); } @Test @@ -302,7 +302,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio .setParam(PARAM_GROUP_NAME, aGroup.getName()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .setParam(PARAM_PROJECT_ID, project.uuid()) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute(); }) .isInstanceOf(BadRequestException.class) @@ -338,7 +338,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio newRequest() .setParam(PARAM_GROUP_NAME, aGroup.getName()) .setParam(PARAM_PERMISSION, PROVISIONING) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute(); }) .isInstanceOf(ForbiddenException.class); @@ -457,13 +457,13 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio assertThatThrownBy(() -> { newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getDbKey()) + .setParam(PARAM_PROJECT_KEY, branch.getKey()) .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getDbKey())); + .hasMessage(format("Project key '%s' not found", branch.getKey())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java index 3b808431776..edefb4dd756 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java @@ -165,7 +165,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .setParam(PARAM_PERMISSION, ISSUE_ADMIN) .execute(); @@ -181,7 +181,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) - .setParam(PARAM_PROJECT_KEY, view.getDbKey()) + .setParam(PARAM_PROJECT_KEY, view.getKey()) .setParam(PARAM_PERMISSION, ISSUE_ADMIN) .execute(); @@ -258,7 +258,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> .execute(); }) .isInstanceOf(BadRequestException.class) - .hasMessage("Component '" + file.getDbKey() + "' (id: " + file.uuid() + ") must be a project or a view."); + .hasMessage("Component '" + file.getKey() + "' (id: " + file.uuid() + ") must be a project or a view."); } @Test @@ -309,7 +309,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PROJECT_ID, project.uuid()) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute(); }) .isInstanceOf(BadRequestException.class) @@ -338,7 +338,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PERMISSION, ISSUE_ADMIN) - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute(); }) .isInstanceOf(ForbiddenException.class); @@ -404,13 +404,13 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> assertThatThrownBy(() -> { newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getDbKey()) + .setParam(PARAM_PROJECT_KEY, branch.getKey()) .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getDbKey())); + .hasMessage(format("Project key '%s' not found", branch.getKey())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java index d266cc43f53..c562e222e7d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java @@ -336,13 +336,13 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> { assertThatThrownBy(() -> { newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getDbKey()) + .setParam(PARAM_PROJECT_KEY, branch.getKey()) .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getDbKey())); + .hasMessage(format("Project key '%s' not found", branch.getKey())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java index 8aa93341310..6479200d64e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java @@ -48,7 +48,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.sonar.api.resources.Qualifiers.APP; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.api.resources.Qualifiers.VIEW; -import static org.sonar.api.web.UserRole.CODEVIEWER; import static org.sonar.db.permission.GlobalPermission.SCAN; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY; @@ -130,7 +129,7 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA public void apply_template_with_project_key() { loginAsAdmin(); - newRequest(template1.getUuid(), null, project.getDbKey()); + newRequest(template1.getUuid(), null, project.getKey()); assertTemplate1AppliedToProject(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java index f1807957cfa..c8d74ba4323 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java @@ -178,11 +178,11 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT @Test public void apply_template_by_query_on_name_and_key_public_project() { - ComponentDto publicProjectFoundByKey = ComponentTesting.newPublicProjectDto().setDbKey("sonar"); + ComponentDto publicProjectFoundByKey = ComponentTesting.newPublicProjectDto().setKey("sonar"); db.components().insertProjectAndSnapshot(publicProjectFoundByKey); ComponentDto publicProjectFoundByName = ComponentTesting.newPublicProjectDto().setName("name-sonar-name"); db.components().insertProjectAndSnapshot(publicProjectFoundByName); - ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto().setDbKey("new-sona").setName("project-name"); + ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto().setKey("new-sona").setName("project-name"); db.components().insertProjectAndSnapshot(projectUntouched); loginAsAdmin(); @@ -199,11 +199,11 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT @Test public void apply_template_by_query_on_name_and_key() { // partial match on key - ComponentDto privateProjectFoundByKey = ComponentTesting.newPrivateProjectDto().setDbKey("sonarqube"); + ComponentDto privateProjectFoundByKey = ComponentTesting.newPrivateProjectDto().setKey("sonarqube"); db.components().insertProjectAndSnapshot(privateProjectFoundByKey); ComponentDto privateProjectFoundByName = ComponentTesting.newPrivateProjectDto().setName("name-sonar-name"); db.components().insertProjectAndSnapshot(privateProjectFoundByName); - ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto().setDbKey("new-sona").setName("project-name"); + ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto().setKey("new-sona").setName("project-name"); db.components().insertProjectAndSnapshot(projectUntouched); loginAsAdmin(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java index a831c480453..aeece4adf7d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java @@ -89,7 +89,7 @@ public class BulkDeleteActionTest { ComponentDto toKeep = db.components().insertPrivateProject(); TestResponse result = ws.newRequest() - .setParam(PARAM_PROJECTS, project1ToDelete.getDbKey() + "," + project2ToDelete.getDbKey()) + .setParam(PARAM_PROJECTS, project1ToDelete.getKey() + "," + project2ToDelete.getKey()) .execute(); assertThat(result.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT); @@ -106,7 +106,7 @@ public class BulkDeleteActionTest { ComponentDto toKeep = db.components().insertPrivateProject(); ws.newRequest() - .setParam(PARAM_PROJECTS, toDeleteInOrg1.getDbKey() + "," + toDeleteInOrg2.getDbKey()) + .setParam(PARAM_PROJECTS, toDeleteInOrg1.getKey() + "," + toDeleteInOrg2.getKey()) .execute(); verifyComponentDeleted(toDeleteInOrg1, toDeleteInOrg2); @@ -136,7 +136,7 @@ public class BulkDeleteActionTest { ComponentDto toDelete2 = db.components().insertPrivateProject(); ws.newRequest() - .setParam("projects", toDelete1.getDbKey() + ",missing," + toDelete2.getDbKey() + ",doesNotExist") + .setParam("projects", toDelete1.getKey() + ",missing," + toDelete2.getKey() + ",doesNotExist") .execute(); verifyComponentDeleted(toDelete1, toDelete2); @@ -207,9 +207,9 @@ public class BulkDeleteActionTest { @Test public void delete_by_key_query_with_partial_match_case_insensitive() { userSession.logIn().addPermission(ADMINISTER); - ComponentDto matchKeyProject = db.components().insertPrivateProject(p -> p.setDbKey("project-_%-key")); - ComponentDto matchUppercaseKeyProject = db.components().insertPrivateProject(p -> p.setDbKey("PROJECT-_%-KEY")); - ComponentDto noMatchProject = db.components().insertPrivateProject(p -> p.setDbKey("project-key-without-escaped-characters")); + ComponentDto matchKeyProject = db.components().insertPrivateProject(p -> p.setKey("project-_%-key")); + ComponentDto matchUppercaseKeyProject = db.components().insertPrivateProject(p -> p.setKey("PROJECT-_%-KEY")); + ComponentDto noMatchProject = db.components().insertPrivateProject(p -> p.setKey("project-key-without-escaped-characters")); ws.newRequest().setParam(Param.TEXT_QUERY, "JeCt-_%-k").execute(); @@ -224,7 +224,7 @@ public class BulkDeleteActionTest { public void delete_only_the_1000_first_projects() { userSession.logIn().addPermission(ADMINISTER); List<String> keys = IntStream.range(0, 1_010).mapToObj(i -> "key" + i).collect(MoreCollectors.toArrayList()); - keys.forEach(key -> db.components().insertPrivateProject(p -> p.setDbKey(key))); + keys.forEach(key -> db.components().insertPrivateProject(p -> p.setKey(key))); ws.newRequest() .setParam("projects", StringUtils.join(keys, ",")) @@ -251,7 +251,7 @@ public class BulkDeleteActionTest { try { ws.newRequest() - .setParam("projects", project1.getDbKey() + "," + project2.getDbKey() + "," + project3.getDbKey()) + .setParam("projects", project1.getKey() + "," + project2.getKey() + "," + project3.getKey()) .execute(); } catch (RuntimeException e) { assertThat(e).isSameAs(expectedException); @@ -266,7 +266,7 @@ public class BulkDeleteActionTest { ComponentDto toDelete2 = db.components().insertPrivateProject(); ws.newRequest() - .setParam("projects", toDelete1.getDbKey() + "," + toDelete2.getDbKey()) + .setParam("projects", toDelete1.getKey() + "," + toDelete2.getKey()) .execute(); verifyComponentDeleted(toDelete1, toDelete2); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/CreateActionTest.java index 881b3c69907..d1ce1d3938e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/CreateActionTest.java @@ -92,29 +92,6 @@ public class CreateActionTest { } @Test - public void fail_if_invalid_project_name() { - userSession.addPermission(PROVISION_PROJECTS); - - var createRequestBRANCHinKey = CreateRequest.builder() - .setProjectKey("test:BRANCH:test") - .setName(DEFAULT_PROJECT_NAME) - .build(); - assertThatThrownBy(() -> call(createRequestBRANCHinKey)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContainingAll("Invalid project key. Project key must not contain following phrases", - ":PULLREQUEST:", ":BRANCH:"); - - var createRequestPRinKey = CreateRequest.builder() - .setProjectKey("test:PULLREQUEST:test") - .setName(DEFAULT_PROJECT_NAME) - .build(); - assertThatThrownBy(() -> call(createRequestPRinKey)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContainingAll("Invalid project key. Project key must not contain following phrases", - ":PULLREQUEST:", ":BRANCH:"); - } - - @Test public void create_project() { userSession.addPermission(PROVISION_PROJECTS); @@ -127,7 +104,7 @@ public class CreateActionTest { .extracting(Project::getKey, Project::getName, Project::getQualifier, Project::getVisibility) .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "public"); assertThat(db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get()) - .extracting(ComponentDto::getDbKey, ComponentDto::name, ComponentDto::qualifier, ComponentDto::scope, ComponentDto::isPrivate, ComponentDto::getMainBranchProjectUuid) + .extracting(ComponentDto::getKey, ComponentDto::name, ComponentDto::qualifier, ComponentDto::scope, ComponentDto::isPrivate, ComponentDto::getMainBranchProjectUuid) .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "PRJ", false, null); } @@ -230,7 +207,7 @@ public class CreateActionTest { @Test public void fail_when_project_already_exists() { - db.components().insertPublicProject(project -> project.setDbKey(DEFAULT_PROJECT_KEY)); + db.components().insertPublicProject(project -> project.setKey(DEFAULT_PROJECT_KEY)); userSession.addPermission(PROVISION_PROJECTS); CreateRequest request = CreateRequest.builder() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java index 7beba7fd6a3..0d4e3e61136 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java @@ -87,9 +87,9 @@ public class DeleteActionTest { ComponentDto project = componentDbTester.insertPrivateProject(); userSessionRule.logIn().addPermission(ADMINISTER); - call(tester.newRequest().setParam(PARAM_PROJECT, project.getDbKey())); + call(tester.newRequest().setParam(PARAM_PROJECT, project.getKey())); - assertThat(verifyDeletedKey()).isEqualTo(project.getDbKey()); + assertThat(verifyDeletedKey()).isEqualTo(project.getKey()); verify(projectLifeCycleListeners).onProjectsDeleted(singleton(Project.from(project))); } @@ -98,9 +98,9 @@ public class DeleteActionTest { ComponentDto project = componentDbTester.insertPrivateProject(); userSessionRule.logIn().addProjectPermission(ADMIN, project); - call(tester.newRequest().setParam(PARAM_PROJECT, project.getDbKey())); + call(tester.newRequest().setParam(PARAM_PROJECT, project.getKey())); - assertThat(verifyDeletedKey()).isEqualTo(project.getDbKey()); + assertThat(verifyDeletedKey()).isEqualTo(project.getKey()); verify(projectLifeCycleListeners).onProjectsDeleted(singleton(Project.from(project))); } @@ -117,7 +117,7 @@ public class DeleteActionTest { new WsActionTester(underTest) .newRequest() - .setParam(PARAM_PROJECT, project.getDbKey()) + .setParam(PARAM_PROJECT, project.getKey()) .execute(); UserDto userReloaded = dbClient.userDao().selectByUuid(dbSession, insert.getUuid()); @@ -156,7 +156,7 @@ public class DeleteActionTest { .addProjectPermission(UserRole.ISSUE_ADMIN, project) .addProjectPermission(UserRole.USER, project); - TestRequest request = tester.newRequest().setParam(PARAM_PROJECT, project.getDbKey()); + TestRequest request = tester.newRequest().setParam(PARAM_PROJECT, project.getKey()); assertThatThrownBy(() -> call(request)) .isInstanceOf(ForbiddenException.class); } @@ -167,7 +167,7 @@ public class DeleteActionTest { userSessionRule.anonymous(); - TestRequest request = tester.newRequest().setParam(PARAM_PROJECT, project.getDbKey()); + TestRequest request = tester.newRequest().setParam(PARAM_PROJECT, project.getKey()); assertThatThrownBy(() -> call(request)) .isInstanceOf(UnauthorizedException.class); } @@ -178,10 +178,10 @@ public class DeleteActionTest { userSessionRule.logIn().addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); - TestRequest request = tester.newRequest().setParam(PARAM_PROJECT, branch.getDbKey()); + TestRequest request = tester.newRequest().setParam(PARAM_PROJECT, branch.getKey()); assertThatThrownBy(() -> call(request)) .isInstanceOf(NotFoundException.class) - .hasMessage(String.format("Project '%s' not found", branch.getDbKey())); + .hasMessage(String.format("Project '%s' not found", branch.getKey())); } private String verifyDeletedKey() { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/ProjectFinderTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/ProjectFinderTest.java index 7fa18411245..cea96bce6b8 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/ProjectFinderTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/ProjectFinderTest.java @@ -58,10 +58,10 @@ public class ProjectFinderTest { @Test public void sort_project_by_name() { - ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); - ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:three").setName("Projet Trois")); - ProjectDto project4 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:four").setName("Projet Quatre")); + ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); + ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setKey("project:three").setName("Projet Trois")); + ProjectDto project4 = db.components().insertPrivateProjectDto(p -> p.setKey("project:four").setName("Projet Quatre")); userSession.addProjectPermission(SCAN, project1, project2, project3, project4); assertThat(underTest.search(db.getSession(), "projet") @@ -72,11 +72,11 @@ public class ProjectFinderTest { @Test public void projects_are_filtered_by_permissions() { - ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); - ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:three").setName("Projet Trois")); - ProjectDto project4 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:four").setName("Projet Quatre")); - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:five").setName("Projet Cinq")); + ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); + ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setKey("project:three").setName("Projet Trois")); + ProjectDto project4 = db.components().insertPrivateProjectDto(p -> p.setKey("project:four").setName("Projet Quatre")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:five").setName("Projet Cinq")); userSession.addProjectPermission(SCAN, project1, project2, project3, project4); @@ -93,11 +93,11 @@ public class ProjectFinderTest { @Test public void projects_are_not_filtered_due_to_global_scan_permission() { - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:three").setName("Projet Trois")); - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:four").setName("Projet Quatre")); - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:five").setName("Projet Cinq")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:three").setName("Projet Trois")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:four").setName("Projet Quatre")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:five").setName("Projet Cinq")); userSession.addPermission(GlobalPermission.SCAN); @@ -115,10 +115,10 @@ public class ProjectFinderTest { @Test public void search_by_query_on_name_case_insensitive() { - ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); - ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:three").setName("Projet Trois")); - ProjectDto project4 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:four").setName("Projet Quatre")); + ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); + ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setKey("project:three").setName("Projet Trois")); + ProjectDto project4 = db.components().insertPrivateProjectDto(p -> p.setKey("project:four").setName("Projet Quatre")); userSession.addProjectPermission(SCAN, project1, project2, project3, project4); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchActionTest.java index d220ecd2bcf..509db5f4ee9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchActionTest.java @@ -87,9 +87,9 @@ public class SearchActionTest { public void search_by_key_query_with_partial_match_case_insensitive() { userSession.addPermission(ADMINISTER); db.components().insertComponents( - ComponentTesting.newPrivateProjectDto().setDbKey("project-_%-key"), - ComponentTesting.newPrivateProjectDto().setDbKey("PROJECT-_%-KEY"), - ComponentTesting.newPrivateProjectDto().setDbKey("project-key-without-escaped-characters")); + ComponentTesting.newPrivateProjectDto().setKey("project-_%-key"), + ComponentTesting.newPrivateProjectDto().setKey("PROJECT-_%-KEY"), + ComponentTesting.newPrivateProjectDto().setKey("project-key-without-escaped-characters")); SearchWsResponse response = call(SearchRequest.builder().setQuery("JeCt-_%-k").build()); @@ -100,8 +100,8 @@ public class SearchActionTest { public void search_private_projects() { userSession.addPermission(ADMINISTER); db.components().insertComponents( - ComponentTesting.newPrivateProjectDto().setDbKey("private-key"), - ComponentTesting.newPublicProjectDto().setDbKey("public-key")); + ComponentTesting.newPrivateProjectDto().setKey("private-key"), + ComponentTesting.newPublicProjectDto().setKey("public-key")); SearchWsResponse response = call(SearchRequest.builder().setVisibility("private").build()); @@ -112,8 +112,8 @@ public class SearchActionTest { public void search_public_projects() { userSession.addPermission(ADMINISTER); db.components().insertComponents( - ComponentTesting.newPrivateProjectDto().setDbKey("private-key"), - ComponentTesting.newPublicProjectDto().setDbKey("public-key")); + ComponentTesting.newPrivateProjectDto().setKey("private-key"), + ComponentTesting.newPublicProjectDto().setKey("public-key")); SearchWsResponse response = call(SearchRequest.builder().setVisibility("public").build()); @@ -124,7 +124,7 @@ public class SearchActionTest { public void search_projects_when_no_qualifier_set() { userSession.addPermission(ADMINISTER); db.components().insertComponents( - ComponentTesting.newPrivateProjectDto().setDbKey(PROJECT_KEY_1), + ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_1), newPortfolio()); SearchWsResponse response = call(SearchRequest.builder().build()); @@ -135,13 +135,13 @@ public class SearchActionTest { @Test public void search_projects() { userSession.addPermission(ADMINISTER); - ComponentDto project = ComponentTesting.newPrivateProjectDto().setDbKey(PROJECT_KEY_1); + ComponentDto project = ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_1); ComponentDto module = newModuleDto(project); ComponentDto directory = newDirectory(module, "dir"); ComponentDto file = newFileDto(directory); db.components().insertComponents( project, module, directory, file, - ComponentTesting.newPrivateProjectDto().setDbKey(PROJECT_KEY_2), + ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_2), newPortfolio()); SearchWsResponse response = call(SearchRequest.builder().setQualifiers(singletonList("TRK")).build()); @@ -153,8 +153,8 @@ public class SearchActionTest { public void search_views() { userSession.addPermission(ADMINISTER); db.components().insertComponents( - ComponentTesting.newPrivateProjectDto().setDbKey(PROJECT_KEY_1), - newPortfolio().setDbKey("view1")); + ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_1), + newPortfolio().setKey("view1")); SearchWsResponse response = call(SearchRequest.builder().setQualifiers(singletonList("VW")).build()); @@ -165,8 +165,8 @@ public class SearchActionTest { public void search_projects_and_views() { userSession.addPermission(ADMINISTER); db.components().insertComponents( - ComponentTesting.newPrivateProjectDto().setDbKey(PROJECT_KEY_1), - newPortfolio().setDbKey("view1")); + ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_1), + newPortfolio().setKey("view1")); SearchWsResponse response = call(SearchRequest.builder().setQualifiers(asList("TRK", "VW")).build()); @@ -177,9 +177,9 @@ public class SearchActionTest { public void search_all() { userSession.addPermission(ADMINISTER); db.components().insertComponents( - ComponentTesting.newPrivateProjectDto().setDbKey(PROJECT_KEY_1), - ComponentTesting.newPrivateProjectDto().setDbKey(PROJECT_KEY_2), - ComponentTesting.newPrivateProjectDto().setDbKey(PROJECT_KEY_3)); + ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_1), + ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_2), + ComponentTesting.newPrivateProjectDto().setKey(PROJECT_KEY_3)); SearchWsResponse response = call(SearchRequest.builder().build()); @@ -227,7 +227,7 @@ public class SearchActionTest { SearchWsResponse response = call(SearchRequest.builder().build()); - assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getDbKey()); + assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getKey()); } @Test @@ -235,7 +235,7 @@ public class SearchActionTest { userSession.addPermission(ADMINISTER); List<ComponentDto> componentDtoList = new ArrayList<>(); for (int i = 1; i <= 9; i++) { - componentDtoList.add(newPrivateProjectDto("project-uuid-" + i).setDbKey("project-key-" + i).setName("Project Name " + i)); + componentDtoList.add(newPrivateProjectDto("project-uuid-" + i).setKey("project-key-" + i).setName("Project Name " + i)); } db.components().insertComponents(componentDtoList.toArray(new ComponentDto[] {})); @@ -358,8 +358,8 @@ public class SearchActionTest { @Test public void json_example() { userSession.addPermission(ADMINISTER); - ComponentDto publicProject = newPrivateProjectDto("project-uuid-1").setName("Project Name 1").setDbKey("project-key-1").setPrivate(false); - ComponentDto privateProject = newPrivateProjectDto("project-uuid-2").setName("Project Name 1").setDbKey("project-key-2"); + ComponentDto publicProject = newPrivateProjectDto("project-uuid-1").setName("Project Name 1").setKey("project-key-1").setPrivate(false); + ComponentDto privateProject = newPrivateProjectDto("project-uuid-2").setName("Project Name 1").setKey("project-key-2"); db.components().insertComponents( publicProject, privateProject); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java index 6ff60570471..818bcd37cce 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java @@ -193,7 +193,7 @@ public class SearchMyProjectsActionTest { assertThat(result.getProjectsList()) .extracting(Project::getKey) - .containsExactlyInAnyOrder(project.getDbKey()); + .containsExactlyInAnyOrder(project.getKey()); } @Test @@ -249,13 +249,13 @@ public class SearchMyProjectsActionTest { private ComponentDto insertClang() { return db.components().insertComponent(newPrivateProjectDto(Uuids.UUID_EXAMPLE_01) .setName("Clang") - .setDbKey("clang")); + .setKey("clang")); } private ComponentDto insertJdk7() { return db.components().insertComponent(newPrivateProjectDto(Uuids.UUID_EXAMPLE_02) .setName("JDK 7") - .setDbKey("net.java.openjdk:jdk7") + .setKey("net.java.openjdk:jdk7") .setDescription("JDK")); } @@ -263,7 +263,7 @@ public class SearchMyProjectsActionTest { String uuid = "752d8bfd-420c-4a83-a4e5-8ab19b13c8fc"; return db.components().insertPublicPortfolio(p -> p.setUuid("752d8bfd-420c-4a83-a4e5-8ab19b13c8fc") .setName("Java") - .setDbKey("Java"), + .setKey("Java"), p -> p.setRootUuid(uuid)); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyScannableProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyScannableProjectsActionTest.java index 1201b6197b0..f8040c36e33 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyScannableProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyScannableProjectsActionTest.java @@ -51,10 +51,10 @@ public class SearchMyScannableProjectsActionTest { @Test public void projects_filtered_by_query() { - ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); - ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:three").setName("Project Three")); - ProjectDto project4 = db.components().insertPublicProjectDto(p -> p.setDbKey("project:four").setName("Project Four")); + ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); + ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setKey("project:three").setName("Project Three")); + ProjectDto project4 = db.components().insertPublicProjectDto(p -> p.setKey("project:four").setName("Project Four")); userSession.addProjectPermission(SCAN, project1, project2, project3, project4); List<Project> result = ws.newRequest() @@ -71,10 +71,10 @@ public class SearchMyScannableProjectsActionTest { @Test public void projects_not_filtered_by_empty_query() { - ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); - ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:three").setName("Project Three")); - ProjectDto project4 = db.components().insertPublicProjectDto(p -> p.setDbKey("project:four").setName("Project Four")); + ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); + ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setKey("project:three").setName("Project Three")); + ProjectDto project4 = db.components().insertPublicProjectDto(p -> p.setKey("project:four").setName("Project Four")); userSession.addProjectPermission(SCAN, project1, project2, project3, project4); List<Project> result = ws.newRequest() @@ -93,10 +93,10 @@ public class SearchMyScannableProjectsActionTest { @Test public void projects_filtered_by_scan_permission() { - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:three").setName("Project Three")); - db.components().insertPublicProjectDto(p -> p.setDbKey("project:four").setName("Project Four")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:three").setName("Project Three")); + db.components().insertPublicProjectDto(p -> p.setKey("project:four").setName("Project Four")); List<Project> result = ws.newRequest() .executeProtobuf(SearchMyScannableProjectsResponse.class) @@ -107,10 +107,10 @@ public class SearchMyScannableProjectsActionTest { @Test public void projects_filtered_for_anonymous_user() { - ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); - ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:three").setName("Project Three")); - ProjectDto project4 = db.components().insertPublicProjectDto(p -> p.setDbKey("project:four").setName("Project Four")); + ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); + ProjectDto project3 = db.components().insertPrivateProjectDto(p -> p.setKey("project:three").setName("Project Three")); + ProjectDto project4 = db.components().insertPublicProjectDto(p -> p.setKey("project:four").setName("Project Four")); userSession.addProjectPermission(SCAN, project1, project2, project3, project4); WsActionTester ws = new WsActionTester( @@ -125,10 +125,10 @@ public class SearchMyScannableProjectsActionTest { @Test public void projects_not_filtered_due_to_global_scan_permission() { - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); - db.components().insertPrivateProjectDto(p -> p.setDbKey("project:three").setName("Project Three")); - db.components().insertPublicProjectDto(p -> p.setDbKey("project:four").setName("Project Four")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:one").setName("Projet Un")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:two").setName("Projet Deux")); + db.components().insertPrivateProjectDto(p -> p.setKey("project:three").setName("Project Three")); + db.components().insertPublicProjectDto(p -> p.setKey("project:four").setName("Project Four")); userSession.addPermission(GlobalPermission.SCAN); List<Project> result = ws.newRequest() @@ -146,9 +146,9 @@ public class SearchMyScannableProjectsActionTest { @Test public void json_example() { - ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project-key-1").setName("Project 1")); - ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project-key-2").setName("Project 2")); - ProjectDto project3 = db.components().insertPublicProjectDto(p -> p.setDbKey("public-project-without-scan-permissions") + ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setKey("project-key-1").setName("Project 1")); + ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setKey("project-key-2").setName("Project 2")); + ProjectDto project3 = db.components().insertPublicProjectDto(p -> p.setKey("public-project-without-scan-permissions") .setName("Public Project with Scan Permissions")); userSession.addProjectPermission(SCAN, project1, project2); userSession.registerProjects(project3); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java index a5e40267741..cc2434b9072 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java @@ -64,9 +64,9 @@ public class UpdateKeyActionTest { ComponentDto project = insertProject(); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - call(project.getDbKey(), ANOTHER_KEY); + call(project.getKey(), ANOTHER_KEY); - assertThat(selectByKey(project.getDbKey())).isEmpty(); + assertThat(selectByKey(project.getKey())).isEmpty(); assertThat(selectByKey(ANOTHER_KEY).get().uuid()).isEqualTo(project.uuid()); } @@ -111,7 +111,7 @@ public class UpdateKeyActionTest { ComponentDto branch = db.components().insertProjectBranch(project); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - String branchDbKey = branch.getDbKey(); + String branchDbKey = branch.getKey(); assertThatThrownBy(() -> call(branchDbKey, ANOTHER_KEY)) .isInstanceOf(NotFoundException.class) .hasMessage(String.format("Project '%s' not found", branchDbKey)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java index 7dc8c17ef28..3c7274a0f03 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java @@ -201,13 +201,13 @@ public class UpdateVisibilityActionTest { userSessionRule.addProjectPermission(UserRole.ADMIN, project, portfolio, application); Stream.of(project, portfolio, application).forEach(c -> request - .setParam(PARAM_PROJECT, c.getDbKey()) + .setParam(PARAM_PROJECT, c.getKey()) .setParam(PARAM_VISIBILITY, randomVisibility) .execute()); Stream.of(module, dir, file, subView, projectCopy) .forEach(nonRootComponent -> { - request.setParam(PARAM_PROJECT, nonRootComponent.getDbKey()) + request.setParam(PARAM_PROJECT, nonRootComponent.getKey()) .setParam(PARAM_VISIBILITY, randomVisibility); try { @@ -222,7 +222,7 @@ public class UpdateVisibilityActionTest { @Test public void execute_throws_ForbiddenException_if_user_has_no_permission_on_specified_component() { ComponentDto project = dbTester.components().insertPrivateProject(); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, randomVisibility); assertThatThrownBy(request::execute) @@ -233,7 +233,7 @@ public class UpdateVisibilityActionTest { @Test public void execute_throws_ForbiddenException_if_user_has_all_permissions_but_ADMIN_on_specified_component() { ComponentDto project = dbTester.components().insertPublicProject(); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, randomVisibility); userSessionRule.addProjectPermission(UserRole.ISSUE_ADMIN, project); Arrays.stream(GlobalPermission.values()) @@ -249,7 +249,7 @@ public class UpdateVisibilityActionTest { public void execute_throws_ForbiddenException_if_user_has_ADMIN_permission_but_sonar_allowPermissionManagementForProjectAdmins_is_set_to_false() { when(configuration.getBoolean(CORE_ALLOW_PERMISSION_MANAGEMENT_FOR_PROJECT_ADMINS_PROPERTY)).thenReturn(of(false)); ComponentDto project = dbTester.components().insertPublicProject(); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, randomVisibility); userSessionRule.addProjectPermission(UserRole.ADMIN, project); @@ -263,7 +263,7 @@ public class UpdateVisibilityActionTest { when(configuration.getBoolean(CORE_ALLOW_PERMISSION_MANAGEMENT_FOR_PROJECT_ADMINS_PROPERTY)).thenReturn(of(false)); ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.setSystemAdministrator().addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, "private"); request.execute(); @@ -276,7 +276,7 @@ public class UpdateVisibilityActionTest { ComponentDto project = randomPublicOrPrivateProject(); IntStream.range(0, 1 + Math.abs(random.nextInt(5))) .forEach(i -> insertPendingTask(project)); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, randomVisibility); userSessionRule.addProjectPermission(UserRole.ADMIN, project); @@ -290,7 +290,7 @@ public class UpdateVisibilityActionTest { ComponentDto project = randomPublicOrPrivateProject(); IntStream.range(0, 1 + Math.abs(random.nextInt(5))) .forEach(i -> insertInProgressTask(project)); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, randomVisibility); userSessionRule.addProjectPermission(UserRole.ADMIN, project); @@ -315,7 +315,7 @@ public class UpdateVisibilityActionTest { dbTester.components().insertComponents(branch, module, dir, file); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, initiallyPrivate ? PUBLIC : PRIVATE) .execute(); @@ -346,7 +346,7 @@ public class UpdateVisibilityActionTest { dbTester.components().insertComponents(branch, module, dir, file); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, initiallyPrivate ? PRIVATE : PUBLIC) .execute(); @@ -365,7 +365,7 @@ public class UpdateVisibilityActionTest { unsafeGiveAllPermissionsToRootComponent(project, user, group); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, PRIVATE) .execute(); @@ -380,7 +380,7 @@ public class UpdateVisibilityActionTest { unsafeGiveAllPermissionsToRootComponent(project, user, group); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, PRIVATE) .execute(); @@ -395,7 +395,7 @@ public class UpdateVisibilityActionTest { unsafeGiveAllPermissionsToRootComponent(project, user, group); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, PUBLIC) .execute(); @@ -410,7 +410,7 @@ public class UpdateVisibilityActionTest { unsafeGiveAllPermissionsToRootComponent(project, user, group); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, PUBLIC) .execute(); @@ -423,7 +423,7 @@ public class UpdateVisibilityActionTest { boolean initiallyPrivate = project.isPrivate(); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, initiallyPrivate ? PUBLIC : PRIVATE) .execute(); @@ -436,7 +436,7 @@ public class UpdateVisibilityActionTest { boolean initiallyPrivate = project.isPrivate(); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, initiallyPrivate ? PRIVATE : PUBLIC) .execute(); @@ -454,7 +454,7 @@ public class UpdateVisibilityActionTest { dbTester.users().insertProjectPermissionOnUser(user2, "p2", project); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, PRIVATE) .execute(); @@ -477,7 +477,7 @@ public class UpdateVisibilityActionTest { dbTester.users().insertProjectPermissionOnGroup(group2, "p2", project); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - request.setParam(PARAM_PROJECT, project.getDbKey()) + request.setParam(PARAM_PROJECT, project.getKey()) .setParam(PARAM_VISIBILITY, PRIVATE) .execute(); @@ -498,7 +498,7 @@ public class UpdateVisibilityActionTest { dbTester.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, portfolio); userSessionRule.addProjectPermission(UserRole.ADMIN, portfolio); - request.setParam(PARAM_PROJECT, portfolio.getDbKey()) + request.setParam(PARAM_PROJECT, portfolio.getKey()) .setParam(PARAM_VISIBILITY, PRIVATE) .execute(); @@ -522,7 +522,7 @@ public class UpdateVisibilityActionTest { dbTester.users().insertProjectPermissionOnUser(user, UserRole.USER, portfolio); dbTester.users().insertProjectPermissionOnUser(user, UserRole.CODEVIEWER, portfolio); - request.setParam(PARAM_PROJECT, portfolio.getDbKey()) + request.setParam(PARAM_PROJECT, portfolio.getKey()) .setParam(PARAM_VISIBILITY, PUBLIC) .execute(); @@ -542,7 +542,7 @@ public class UpdateVisibilityActionTest { dbTester.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, application); userSessionRule.addProjectPermission(UserRole.ADMIN, application); - request.setParam(PARAM_PROJECT, application.getDbKey()) + request.setParam(PARAM_PROJECT, application.getKey()) .setParam(PARAM_VISIBILITY, PRIVATE) .execute(); @@ -566,7 +566,7 @@ public class UpdateVisibilityActionTest { dbTester.users().insertProjectPermissionOnUser(user, UserRole.USER, portfolio); dbTester.users().insertProjectPermissionOnUser(user, UserRole.CODEVIEWER, portfolio); - request.setParam(PARAM_PROJECT, portfolio.getDbKey()) + request.setParam(PARAM_PROJECT, portfolio.getKey()) .setParam(PARAM_VISIBILITY, PUBLIC) .execute(); @@ -583,11 +583,11 @@ public class UpdateVisibilityActionTest { userSessionRule.logIn().addProjectPermission(UserRole.USER, project); ComponentDto branch = dbTester.components().insertProjectBranch(project); - TestRequest request = this.request.setParam(PARAM_PROJECT, branch.getDbKey()) + TestRequest request = this.request.setParam(PARAM_PROJECT, branch.getKey()) .setParam(PARAM_VISIBILITY, PUBLIC); assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) - .hasMessage(String.format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(String.format("Component key '%s' not found", branch.getKey())); } private void unsafeGiveAllPermissionsToRootComponent(ComponentDto component, UserDto user, GroupDto group) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java index cb9f0dbd795..4d6e0c813cc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java @@ -119,7 +119,7 @@ public class SearchActionTest { @Test public void json_example() { - ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey(KEY_PROJECT_EXAMPLE_001)); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setKey(KEY_PROJECT_EXAMPLE_001)); userSession.addProjectPermission(UserRole.USER, project); SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project) @@ -202,7 +202,7 @@ public class SearchActionTest { @Test public void return_only_processed_analyses() { - ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey("P1")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setKey("P1")); userSession.addProjectPermission(UserRole.USER, project); db.components().insertSnapshot(newAnalysis(project).setUuid("A1")); db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setStatus(SnapshotDto.STATUS_UNPROCESSED)); @@ -215,7 +215,7 @@ public class SearchActionTest { @Test public void return_events() { - ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey("P1")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setKey("P1")); userSession.addProjectPermission(UserRole.USER, project); SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1")); SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(ComponentTesting.newPrivateProjectDto()).setUuid("A42")); @@ -241,7 +241,7 @@ public class SearchActionTest { SnapshotDto secondAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(2_000_000L)); SnapshotDto thirdAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(3_000_000L)); - List<Analysis> result = call(application.getDbKey()).getAnalysesList(); + List<Analysis> result = call(application.getKey()).getAnalysesList(); assertThat(result) .hasSize(3) @@ -262,7 +262,7 @@ public class SearchActionTest { EventComponentChangeDto changeDto2 = generateEventComponentChange(event, REMOVED, "Another project", "app2", "master", uuidFactoryFast.create()); insertEventComponentChanges(application, firstAnalysis, changeDto1, changeDto2); - List<Analysis> result = call(application.getDbKey()).getAnalysesList(); + List<Analysis> result = call(application.getKey()).getAnalysesList(); assertThat(result).hasSize(1); List<Event> events = result.get(0).getEventsList(); @@ -287,7 +287,7 @@ public class SearchActionTest { EventComponentChangeDto changeDto2 = generateEventComponentChange(event, ADDED, "My project", "app1", newBranch, changeDto1.getComponentUuid()); insertEventComponentChanges(application, firstAnalysis, changeDto1, changeDto2); - List<Analysis> result = call(application.getDbKey()).getAnalysesList(); + List<Analysis> result = call(application.getKey()).getAnalysesList(); assertThat(result).hasSize(1); List<Event> events = result.get(0).getEventsList(); @@ -312,7 +312,7 @@ public class SearchActionTest { db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto2, eventPurgeData); db.getSession().commit(); - List<Analysis> result = call(application.getDbKey()).getAnalysesList(); + List<Analysis> result = call(application.getKey()).getAnalysesList(); assertThat(result).hasSize(1); List<Event> events = result.get(0).getEventsList(); @@ -339,7 +339,7 @@ public class SearchActionTest { db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData); db.getSession().commit(); - List<Analysis> result = call(application.getDbKey()).getAnalysesList(); + List<Analysis> result = call(application.getKey()).getAnalysesList(); assertThat(result).hasSize(1); List<Event> events = result.get(0).getEventsList(); @@ -369,7 +369,7 @@ public class SearchActionTest { db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto3, eventPurgeData); db.getSession().commit(); - List<Analysis> result = call(application.getDbKey()).getAnalysesList(); + List<Analysis> result = call(application.getKey()).getAnalysesList(); assertThat(result).hasSize(1); List<Event> events = result.get(0).getEventsList(); @@ -401,7 +401,7 @@ public class SearchActionTest { db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData); db.getSession().commit(); - List<Analysis> result = call(application.getDbKey()).getAnalysesList(); + List<Analysis> result = call(application.getKey()).getAnalysesList(); assertThat(result).hasSize(1); List<Event> events = result.get(0).getEventsList(); @@ -426,7 +426,7 @@ public class SearchActionTest { SnapshotDto secondAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(2_000_000L)); SnapshotDto thirdAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(3_000_000L)); - List<Analysis> result = call(view.getDbKey()).getAnalysesList(); + List<Analysis> result = call(view.getKey()).getAnalysesList(); assertThat(result) .hasSize(3) @@ -440,7 +440,7 @@ public class SearchActionTest { IntStream.rangeClosed(1, 9).forEach(i -> db.components().insertSnapshot(newAnalysis(project).setCreatedAt(1_000_000L * i).setUuid("A" + i))); SearchResponse result = call(SearchRequest.builder() - .setProject(project.getDbKey()) + .setProject(project.getKey()) .setPage(2) .setPageSize(3) .build()); @@ -451,7 +451,7 @@ public class SearchActionTest { @Test public void filter_by_category() { - ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey("P1")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setKey("P1")); userSession.addProjectPermission(UserRole.USER, project); SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1")); SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2")); @@ -472,7 +472,7 @@ public class SearchActionTest { @Test public void paginate_with_filter_on_category() { - ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey("P1")); + ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setKey("P1")); userSession.addProjectPermission(UserRole.USER, project); SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L)); SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L)); @@ -507,7 +507,7 @@ public class SearchActionTest { SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(project).setUuid("a4").setCreatedAt(4_000_000_000L)); SearchResponse result = call(SearchRequest.builder() - .setProject(project.getDbKey()) + .setProject(project.getKey()) .setFrom(formatDateTime(2_000_000_000L)) .build()); @@ -527,7 +527,7 @@ public class SearchActionTest { SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(project).setUuid("a4").setCreatedAt(4_000_000_000L)); SearchResponse result = call(SearchRequest.builder() - .setProject(project.getDbKey()) + .setProject(project.getKey()) .setTo(formatDateTime(2_000_000_000L)) .build()); @@ -547,7 +547,7 @@ public class SearchActionTest { SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(project).setUuid("a4").setCreatedAt(4_000_000_000L)); SearchResponse result = call(SearchRequest.builder() - .setProject(project.getDbKey()) + .setProject(project.getKey()) .setFrom(formatDateTime(2_000_000_000L)) .setTo(formatDateTime(3_000_000_000L)) .build()); @@ -568,7 +568,7 @@ public class SearchActionTest { SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(project).setUuid("a4").setCreatedAt(4_000_000_000L)); SearchResponse result = call(SearchRequest.builder() - .setProject(project.getDbKey()) + .setProject(project.getKey()) .setFrom(formatDate(new Date(2_000_000_000L))) .setTo(formatDate(new Date(3_000_000_000L))) .build()); @@ -602,7 +602,7 @@ public class SearchActionTest { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); - SearchResponse result = call(project.getDbKey()); + SearchResponse result = call(project.getKey()); assertThat(result.hasPaging()).isTrue(); assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 0); @@ -620,7 +620,7 @@ public class SearchActionTest { db.components().insertSnapshot(newAnalysis(project).setProjectVersion("c").setBuildString("d")) }; - SearchResponse result = call(project.getDbKey()); + SearchResponse result = call(project.getKey()); assertThat(result.getAnalysesList()) .extracting(Analysis::getKey, Analysis::getProjectVersion, Analysis::getBuildString) @@ -636,7 +636,7 @@ public class SearchActionTest { userSession.anonymous(); ComponentDto project = db.components().insertPrivateProject(); - var projectDbKey = project.getDbKey(); + var projectDbKey = project.getKey(); assertThatThrownBy(() -> call(projectDbKey)) .isInstanceOf(ForbiddenException.class); } @@ -654,7 +654,7 @@ public class SearchActionTest { toProjectDto(project2, 1L)) .addProjectPermission(UserRole.USER, application, project1); - var projectDbKey = application.getDbKey(); + var projectDbKey = application.getKey(); assertThatThrownBy(() -> call(projectDbKey)) .isInstanceOf(ForbiddenException.class); } @@ -672,7 +672,7 @@ public class SearchActionTest { db.components().insertSnapshot(newAnalysis(project)); userSession.registerComponents(project, file); - var fileDbKey = file.getDbKey(); + var fileDbKey = file.getKey(); assertThatThrownBy(() -> call(fileDbKey)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("A project, portfolio or application is required"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/UnsetBaselineActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/UnsetBaselineActionTest.java index 0b0952203fa..3e0e0235361 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/UnsetBaselineActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/UnsetBaselineActionTest.java @@ -101,7 +101,7 @@ public class UnsetBaselineActionTest { ComponentDto branch = db.components().insertProjectBranch(project); SnapshotDto projectAnalysis = db.components().insertSnapshot(project); SnapshotDto branchAnalysis = db.components().insertSnapshot(project); - db.newCodePeriods().insert(project.projectUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, projectAnalysis.getUuid()); + db.newCodePeriods().insert(project.branchUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, projectAnalysis.getUuid()); logInAsProjectAdministrator(project); call(project.getKey(), null); @@ -115,7 +115,7 @@ public class UnsetBaselineActionTest { ComponentDto branch = db.components().insertProjectBranch(project); db.components().insertSnapshot(branch); SnapshotDto branchAnalysis = db.components().insertSnapshot(project); - db.newCodePeriods().insert(project.projectUuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, branchAnalysis.getUuid()); + db.newCodePeriods().insert(project.branchUuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, branchAnalysis.getUuid()); logInAsProjectAdministrator(project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java index d1a69a417ac..231955fd595 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java @@ -66,7 +66,7 @@ public class ExportActionTest { @Before public void setUp() { - project = db.components().insertComponent(newPrivateProjectDto(PROJECT_ID).setDbKey(PROJECT_KEY).setName(PROJECT_NAME)); + project = db.components().insertComponent(newPrivateProjectDto(PROJECT_ID).setKey(PROJECT_KEY).setName(PROJECT_NAME)); } @Test @@ -87,7 +87,7 @@ public class ExportActionTest { public void fails_if_not_project_administrator() { userSession.logIn(); - assertThatThrownBy(() -> actionTester.newRequest().setMethod("POST").setParam("key", project.getDbKey()).execute()) + assertThatThrownBy(() -> actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()).execute()) .isInstanceOf(ForbiddenException.class); } @@ -96,8 +96,8 @@ public class ExportActionTest { UserDto user = db.users().insertUser(); userSession.logIn(user).addProjectPermission(UserRole.ADMIN, project); - when(exportSubmitter.submitProjectExport(project.getDbKey(), user.getUuid())).thenReturn(createResponseExampleTask()); - TestResponse response = actionTester.newRequest().setMethod("POST").setParam("key", project.getDbKey()).execute(); + when(exportSubmitter.submitProjectExport(project.getKey(), user.getUuid())).thenReturn(createResponseExampleTask()); + TestResponse response = actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()).execute(); assertJson(response.getInput()).isSimilarTo(responseExample()); } @@ -106,7 +106,7 @@ public class ExportActionTest { public void fails_to_trigger_task_if_anonymous() { userSession.anonymous(); - assertThatThrownBy(() -> actionTester.newRequest().setMethod("POST").setParam("key", project.getDbKey()).execute()) + assertThatThrownBy(() -> actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()).execute()) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); } @@ -116,8 +116,8 @@ public class ExportActionTest { UserDto user = db.users().insertUser(); userSession.logIn(user).addProjectPermission(UserRole.ADMIN, project); - when(exportSubmitter.submitProjectExport(project.getDbKey(), user.getUuid())).thenReturn(createResponseExampleTask()); - TestResponse response = actionTester.newRequest().setMethod("POST").setParam("key", project.getDbKey()).execute(); + when(exportSubmitter.submitProjectExport(project.getKey(), user.getUuid())).thenReturn(createResponseExampleTask()); + TestResponse response = actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()).execute(); assertJson(response.getInput()).isSimilarTo(responseExample()); } @@ -131,7 +131,7 @@ public class ExportActionTest { assertThatThrownBy(() -> { actionTester.newRequest() .setMethod("POST") - .setParam("key", branch.getDbKey()) + .setParam("key", branch.getKey()) .execute(); }) .isInstanceOf(NotFoundException.class); @@ -146,7 +146,7 @@ public class ExportActionTest { } private CeTask createResponseExampleTask() { - CeTask.Component component = new CeTask.Component(project.uuid(), project.getDbKey(), project.name()); + CeTask.Component component = new CeTask.Component(project.uuid(), project.getKey(), project.name()); return new CeTask.Builder() .setType(CeTaskTypes.PROJECT_EXPORT) .setUuid(TASK_ID) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java index f9f866ef065..6956e15b1db 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java @@ -284,7 +284,7 @@ public class StatusActionTest { assertThatThrownBy(() -> { underTest.newRequest() - .setParam(KEY_PARAM, branch.getDbKey()) + .setParam(KEY_PARAM, branch.getKey()) .execute(); }) .isInstanceOf(NotFoundException.class); @@ -304,7 +304,7 @@ public class StatusActionTest { } private ProjectDto insertProject(String uuid, String key) { - return db.components().insertPrivateProjectDto(c -> c.setProjectUuid(uuid).setUuid(uuid).setDbKey(key)); + return db.components().insertPrivateProjectDto(c -> c.setBranchUuid(uuid).setUuid(uuid).setKey(key)); } private void insertSnapshot(ProjectDto projectDto, boolean last) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java index 1fb0cb9acd6..b222f8cb501 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java @@ -67,7 +67,7 @@ public class CreateActionTest { String result = ws.newRequest() .setMethod("POST") - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .setParam(PARAM_NAME, "Custom") .setParam(PARAM_URL, "http://example.org") .execute().getInput(); @@ -222,12 +222,12 @@ public class CreateActionTest { ComponentDto branch = db.components().insertProjectBranch(project); assertThatThrownBy(() -> ws.newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getDbKey()) + .setParam(PARAM_PROJECT_KEY, branch.getKey()) .setParam(PARAM_NAME, "Custom") .setParam(PARAM_URL, "http://example.org") .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Project '%s' not found", branch.getKey())); } @Test @@ -261,10 +261,10 @@ public class CreateActionTest { assertThatThrownBy(() -> ws.newRequest() .setParam(PARAM_NAME, "Custom") .setParam(PARAM_URL, "http://example.org") - .setParam(PARAM_PROJECT_KEY, component.getDbKey()) + .setParam(PARAM_PROJECT_KEY, component.getKey()) .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining("Project '" + component.getDbKey() + "' not found"); + .hasMessageContaining("Project '" + component.getKey() + "' not found"); } private void failIfNotAProjectWithUuid(ComponentDto root, ComponentDto component) { @@ -282,7 +282,7 @@ public class CreateActionTest { private void createAndTest(ComponentDto project, String name, String url, String type) { ProjectLinks.CreateWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT_KEY, project.getKey()) .setParam(PARAM_NAME, name) .setParam(PARAM_URL, url) .executeProtobuf(ProjectLinks.CreateWsResponse.class); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java index efdb8b69068..892c5f30d8a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java @@ -243,10 +243,10 @@ public class SearchActionTest { ComponentDto branch = db.components().insertProjectBranch(project); assertThatThrownBy(() -> ws.newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getDbKey()) + .setParam(PARAM_PROJECT_KEY, branch.getKey()) .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Project '%s' not found", branch.getKey())); } @Test @@ -292,7 +292,7 @@ public class SearchActionTest { userSession.logIn().addProjectPermission(USER, root); assertThatThrownBy(() -> ws.newRequest() - .setParam(PARAM_PROJECT_KEY, component.getDbKey()) + .setParam(PARAM_PROJECT_KEY, component.getKey()) .execute()) .isInstanceOf(NotFoundException.class) .hasMessageContaining("Project '" + component.getKey() + "' not found"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java index 02017927bce..8620a38a451 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java @@ -110,7 +110,7 @@ public class SearchActionTest { private static ProjectMeasuresDoc newDoc(ComponentDto project) { return new ProjectMeasuresDoc() .setId(project.uuid()) - .setKey(project.getDbKey()) + .setKey(project.getKey()) .setName(project.name()); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java index 902cebb7c18..f252d53598c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java @@ -153,7 +153,7 @@ public class SetActionTest { @Test public void fail_if_component_is_a_view() { - ComponentDto view = db.components().insertPrivatePortfolio(v -> v.setDbKey("VIEW_KEY")); + ComponentDto view = db.components().insertPrivatePortfolio(v -> v.setKey("VIEW_KEY")); String viewKey = view.getKey(); assertThatThrownBy(() -> call(viewKey, "point-of-view")) @@ -164,7 +164,7 @@ public class SetActionTest { @Test public void fail_if_component_is_a_module() { ComponentDto projectComponent = dbClient.componentDao().selectByUuid(dbSession, project.getUuid()).get(); - ComponentDto module = db.components().insertComponent(newModuleDto(projectComponent).setDbKey("MODULE_KEY")); + ComponentDto module = db.components().insertComponent(newModuleDto(projectComponent).setKey("MODULE_KEY")); String moduleKey = module.getKey(); assertThatThrownBy(() -> call(moduleKey, "modz")) @@ -175,7 +175,7 @@ public class SetActionTest { @Test public void fail_if_component_is_a_file() { ComponentDto projectComponent = dbClient.componentDao().selectByUuid(dbSession, project.getUuid()).get(); - ComponentDto file = db.components().insertComponent(newFileDto(projectComponent).setDbKey("FILE_KEY")); + ComponentDto file = db.components().insertComponent(newFileDto(projectComponent).setKey("FILE_KEY")); String fileKey = file.getKey(); assertThatThrownBy(() -> call(fileKey, "secret")) @@ -189,7 +189,7 @@ public class SetActionTest { userSession.logIn().addProjectPermission(USER, project); ComponentDto branch = db.components().insertProjectBranch(project); - String branchDbKey = branch.getDbKey(); + String branchDbKey = branch.getKey(); assertThatThrownBy(() -> call(branchDbKey, "secret")) .isInstanceOf(NotFoundException.class) .hasMessage(format("Project '%s' not found", branchDbKey)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java index ca404418e58..04c2565c6fc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java @@ -167,10 +167,10 @@ public class DeselectActionTest { ComponentDto branch = db.components().insertProjectBranch(project); assertThatThrownBy(() -> ws.newRequest() - .setParam("projectKey", branch.getDbKey()) + .setParam("projectKey", branch.getKey()) .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Project '%s' not found", branch.getKey())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java index a541dba0edc..1b5e676ac90 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java @@ -197,9 +197,9 @@ public class GetByProjectActionTest { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); ComponentDto branch = db.components().insertProjectBranch(project); - assertThatThrownBy(() -> ws.newRequest().setParam("project", branch.getDbKey()).execute()) + assertThatThrownBy(() -> ws.newRequest().setParam("project", branch.getKey()).execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Project '%s' not found", branch.getKey())); } private void logInAsProjectUser(ProjectDto project) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java index f3132c3aa39..a193ae44a12 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java @@ -406,10 +406,10 @@ public class ProjectStatusActionTest { SnapshotDto snapshot = db.components().insertSnapshot(branch); assertThatThrownBy(() -> ws.newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getDbKey()) + .setParam(PARAM_PROJECT_KEY, branch.getKey()) .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Project '%s' not found", branch.getKey())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java index 44a609bdc75..f29daa0519a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java @@ -180,7 +180,7 @@ public class SelectActionTest { assertThatThrownBy(() -> ws.newRequest() .setParam("gateId", qualityGate.getUuid()) - .setParam("projectKey", project.getDbKey()) + .setParam("projectKey", project.getKey()) .execute()) .isInstanceOf(ForbiddenException.class); } @@ -193,7 +193,7 @@ public class SelectActionTest { assertThatThrownBy(() -> ws.newRequest() .setParam("gateId", qualityGate.getUuid()) - .setParam("projectKey", project.getDbKey()) + .setParam("projectKey", project.getKey()) .execute()) .isInstanceOf(ForbiddenException.class); } @@ -207,10 +207,10 @@ public class SelectActionTest { assertThatThrownBy(() -> ws.newRequest() .setParam("gateId", qualityGate.getUuid()) - .setParam("projectKey", branch.getDbKey()) + .setParam("projectKey", branch.getKey()) .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Project '%s' not found", branch.getKey())); } private void assertSelected(QualityGateDto qualityGate, ComponentDto project) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java index a31d95fc0f9..89e3fd257c2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java @@ -217,12 +217,12 @@ public class AddProjectActionTest { assertThatThrownBy(() -> { tester.newRequest() - .setParam("project", branch.getDbKey()) + .setParam("project", branch.getKey()) .setParam("profileKey", profile.getKee()) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project '%s' not found", branch.getDbKey())); + .hasMessage(format("Project '%s' not found", branch.getKey())); } private void assertProjectIsAssociatedToProfile(ProjectDto project, QProfileDto profile) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java index 45683a0bb18..8ee6be6c799 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java @@ -205,7 +205,7 @@ public class RemoveProjectActionTest { assertThatThrownBy(() -> { ws.newRequest() - .setParam("project", project.getDbKey()) + .setParam("project", project.getKey()) .setParam("language", "xoo") .setParam("qualityProfile", "unknown") .execute(); @@ -223,13 +223,13 @@ public class RemoveProjectActionTest { assertThatThrownBy(() -> { ws.newRequest() - .setParam("project", branch.getDbKey()) + .setParam("project", branch.getKey()) .setParam("language", profile.getLanguage()) .setParam("qualityProfile", profile.getName()) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project '%s' not found", branch.getDbKey())); + .hasMessage(format("Project '%s' not found", branch.getKey())); } private void assertProjectIsAssociatedToProfile(ProjectDto project, QProfileDto profile) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java index 8e9b9131ed4..8dac5638c8a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java @@ -282,7 +282,7 @@ public class ListDefinitionsActionTest { .onQualifiers(PROJECT) .build()); - ListDefinitionsWsResponse result = executeRequest(project.getDbKey()); + ListDefinitionsWsResponse result = executeRequest(project.getKey()); assertThat(result.getDefinitionsList()).hasSize(1); } @@ -310,7 +310,7 @@ public class ListDefinitionsActionTest { PropertyDefinition.builder("only-on-project").onlyOnQualifiers(PROJECT).build(), PropertyDefinition.builder("only-on-module").onlyOnQualifiers(MODULE).build())); - ListDefinitionsWsResponse result = executeRequest(project.getDbKey()); + ListDefinitionsWsResponse result = executeRequest(project.getKey()); assertThat(result.getDefinitionsList()).extracting("key").containsOnly("global-and-project", "only-on-project"); } @@ -380,7 +380,7 @@ public class ListDefinitionsActionTest { PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(), PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build())); - ListDefinitionsWsResponse result = executeRequest(project.getDbKey()); + ListDefinitionsWsResponse result = executeRequest(project.getKey()); assertThat(result.getDefinitionsList()).extracting(Definition::getKey).containsOnly("foo", "secret.secured"); } @@ -390,7 +390,7 @@ public class ListDefinitionsActionTest { userSession.logIn("project-admin").addProjectPermission(CODEVIEWER, project); propertyDefinitions.addComponent(PropertyDefinition.builder("foo").build()); - assertThatThrownBy(() -> executeRequest(project.getDbKey())) + assertThatThrownBy(() -> executeRequest(project.getKey())) .isInstanceOf(ForbiddenException.class); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java index 954f7ea4468..bfd3ba794f8 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java @@ -376,11 +376,11 @@ public class ResetActionTest { assertThatThrownBy(() -> { ws.newRequest() .setParam("keys", "foo") - .setParam("component", branch.getDbKey()) + .setParam("component", branch.getKey()) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } @Test @@ -451,11 +451,11 @@ public class ResetActionTest { } private void executeRequestOnProjectSetting(String key) { - executeRequest(key, project.getDbKey()); + executeRequest(key, project.getKey()); } private void executeRequestOnComponentSetting(String key, ComponentDto componentDto) { - executeRequest(key, componentDto.getDbKey()); + executeRequest(key, componentDto.getKey()); } private void executeRequest(String key, @Nullable String componentKey) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java index c1f00e84715..59e1e725091 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java @@ -150,7 +150,7 @@ public class SetActionTest { ComponentDto project = db.components().insertPrivateProject(); logInAsProjectAdministrator(project); - callForProjectSettingByKey("my.key", "my project value", project.getDbKey()); + callForProjectSettingByKey("my.key", "my project value", project.getKey()); assertGlobalSetting("my.key", "my global value"); assertComponentSetting("my.key", "my project value", project.uuid()); @@ -162,7 +162,7 @@ public class SetActionTest { ComponentDto project = db.components().insertPrivateProject(); logInAsProjectAdministrator(project); - callForProjectSettingByKey("my.key", "my value", project.getDbKey()); + callForProjectSettingByKey("my.key", "my value", project.getKey()); assertComponentSetting("my.key", "my value", project.uuid()); } @@ -177,7 +177,7 @@ public class SetActionTest { assertComponentSetting("my.key", "my project value", project.uuid()); logInAsProjectAdministrator(project); - callForProjectSettingByKey("my.key", "my new project value", project.getDbKey()); + callForProjectSettingByKey("my.key", "my new project value", project.getKey()); assertComponentSetting("my.key", "my new project value", project.uuid()); } @@ -317,10 +317,10 @@ public class SetActionTest { callForComponentPropertySet("my.key", newArrayList( GSON.toJson(ImmutableMap.of("firstField", "firstValue", "secondField", "secondValue")), GSON.toJson(ImmutableMap.of("firstField", "anotherFirstValue", "secondField", "anotherSecondValue"))), - project.getDbKey()); + project.getKey()); assertThat(dbClient.propertiesDao().selectGlobalProperties(dbSession)).hasSize(3); - assertThat(dbClient.propertiesDao().selectProjectProperties(dbSession, project.getDbKey())).hasSize(5); + assertThat(dbClient.propertiesDao().selectProjectProperties(dbSession, project.getKey())).hasSize(5); assertGlobalSetting("my.key", "1"); assertGlobalSetting("my.key.1.firstField", "oldFirstValue"); assertGlobalSetting("my.key.1.secondField", "oldSecondValue"); @@ -803,7 +803,7 @@ public class SetActionTest { assertThatThrownBy(() -> { logInAsProjectAdministrator(view); - callForProjectSettingByKey("my.key", "My Value", view.getDbKey()); + callForProjectSettingByKey("my.key", "My Value", view.getKey()); }) .isInstanceOf(BadRequestException.class) .hasMessage("Setting 'my.key' cannot be set on a View"); @@ -827,7 +827,7 @@ public class SetActionTest { logInAsProjectAdministrator(project); assertThatThrownBy(() -> { - callForProjectSettingByKey("my.key", "My Value", file.getDbKey()); + callForProjectSettingByKey("my.key", "My Value", file.getKey()); }) .isInstanceOf(BadRequestException.class) .hasMessage("Setting 'my.key' cannot be set on a CptLabel"); @@ -884,7 +884,7 @@ public class SetActionTest { private void succeedForPropertyWithoutDefinitionAndValidComponent(ComponentDto project, ComponentDto module) { logInAsProjectAdministrator(project); - callForProjectSettingByKey("my.key", "My Value", module.getDbKey()); + callForProjectSettingByKey("my.key", "My Value", module.getKey()); assertComponentSetting("my.key", "My Value", module.uuid()); } @@ -894,7 +894,7 @@ public class SetActionTest { logInAsProjectAdministrator(root); assertThatThrownBy(() -> { - callForProjectSettingByKey("my.key", "My Value", component.getDbKey()); + callForProjectSettingByKey("my.key", "My Value", component.getKey()); }) .isInstanceOf(BadRequestException.class) .hasMessage("Setting 'my.key' cannot be set on a QualifierLabel"); @@ -1154,7 +1154,7 @@ public class SetActionTest { assertThatThrownBy(() -> { callForComponentPropertySet("my.key", newArrayList( - GSON.toJson(ImmutableMap.of("firstField", "firstValue"))), project.getDbKey()); + GSON.toJson(ImmutableMap.of("firstField", "firstValue"))), project.getKey()); }) .isInstanceOf(BadRequestException.class) .hasMessage("Setting 'my.key' cannot be set on a Project"); @@ -1167,10 +1167,10 @@ public class SetActionTest { ComponentDto branch = db.components().insertProjectBranch(project); assertThatThrownBy(() -> { - callForProjectSettingByKey("my.key", "My Value", branch.getDbKey()); + callForProjectSettingByKey("my.key", "My Value", branch.getKey()); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java index d1b67a3181b..20703ac513a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java @@ -748,7 +748,7 @@ public class ValuesActionTest { definitions.addComponent(PropertyDefinition.builder("foo").build()); assertThatThrownBy(() -> { - executeRequest(project.getDbKey(), "foo"); + executeRequest(project.getKey(), "foo"); }) .isInstanceOf(ForbiddenException.class); } @@ -828,11 +828,11 @@ public class ValuesActionTest { assertThatThrownBy(() -> { newTester().newRequest() .setParam("keys", "foo") - .setParam("component", branch.getDbKey()) + .setParam("component", branch.getKey()) .execute(); }) .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getDbKey())); + .hasMessage(format("Component key '%s' not found", branch.getKey())); } @Test @@ -894,11 +894,11 @@ public class ValuesActionTest { } private ValuesWsResponse executeRequestForComponentProperties(ComponentDto componentDto, String... keys) { - return executeRequest(componentDto.getDbKey(), keys); + return executeRequest(componentDto.getKey(), keys); } private ValuesWsResponse executeRequestForProjectProperties(String... keys) { - return executeRequest(project.getDbKey(), keys); + return executeRequest(project.getKey(), keys); } private ValuesWsResponse executeRequestForGlobalProperties(String... keys) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IndexActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IndexActionTest.java index b44b1dc7754..66c679194eb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IndexActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IndexActionTest.java @@ -61,7 +61,7 @@ public class IndexActionTest { insertFileWithData(file, newData("public class HelloWorld {", "}")); TestResponse request = tester.newRequest() - .setParam("resource", file.getDbKey()) + .setParam("resource", file.getKey()) .execute(); assertJson(request.getInput()).isSimilarTo("[\n" + @@ -80,7 +80,7 @@ public class IndexActionTest { insertFileWithData(file, newData("/**", " */", "public class HelloWorld {", "}", "", "foo")); TestResponse request = tester.newRequest() - .setParam("resource", file.getDbKey()) + .setParam("resource", file.getKey()) .setParam("from", "3") .setParam("to", "5") .execute(); @@ -100,7 +100,7 @@ public class IndexActionTest { ComponentDto file = db.components().insertComponent(newFileDto(project)); assertThatThrownBy(() -> tester.newRequest() - .setParam("resource", file.getDbKey()) + .setParam("resource", file.getKey()) .execute()) .isInstanceOf(ForbiddenException.class); } @@ -120,10 +120,10 @@ public class IndexActionTest { userSession.addProjectPermission(USER, project); assertThatThrownBy(() -> tester.newRequest() - .setParam("resource", branch.getDbKey()) + .setParam("resource", branch.getKey()) .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); } private static DbFileSources.Data newData(String... lines) { @@ -140,7 +140,7 @@ public class IndexActionTest { private void insertFileWithData(ComponentDto file, DbFileSources.Data fileData) { db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto() .setUuid(Uuids.createFast()) - .setProjectUuid(file.projectUuid()) + .setProjectUuid(file.branchUuid()) .setFileUuid(file.uuid()) .setSourceData(fileData)); db.commit(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java index c886d4a1ad3..fbbf4782250 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java @@ -186,7 +186,7 @@ public class LinesActionTest { @Test public void fail_when_file_is_removed() { ComponentDto privateProject = db.components().insertPrivateProject(); - ComponentDto file = newFileDto(privateProject).setDbKey("file-key").setEnabled(false); + ComponentDto file = newFileDto(privateProject).setKey("file-key").setEnabled(false); db.components().insertComponents(file); setUserWithValidPermission(file); @@ -334,10 +334,10 @@ public class LinesActionTest { userSession.addProjectPermission(UserRole.USER, project); assertThatThrownBy(() -> tester.newRequest() - .setParam("key", branch.getDbKey()) + .setParam("key", branch.getKey()) .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); } @Test @@ -393,7 +393,7 @@ public class LinesActionTest { ComponentDto file = insertFile(project); db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto() .setUuid(Uuids.createFast()) - .setProjectUuid(project.projectUuid()) + .setProjectUuid(project.branchUuid()) .setFileUuid(file.uuid()) .setSourceData(fileData)); db.commit(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java index a37f173920f..94f61d8448a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java @@ -67,7 +67,7 @@ public class ScmActionTest { @Before public void setUp() { project = dbTester.components().insertPrivateProject(PROJECT_UUID); - file = ComponentTesting.newFileDto(project, null, FILE_UUID).setDbKey(FILE_KEY); + file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY); dbClient.componentDao().insert(dbTester.getSession(), file); dbTester.getSession().commit(); } @@ -222,10 +222,10 @@ public class ScmActionTest { userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); assertThatThrownBy(() -> tester.newRequest() - .setParam("key", branch.getDbKey()) + .setParam("key", branch.getKey()) .execute()) .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getDbKey())); + .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); } private DbFileSources.Line newSourceLine(String author, String revision, Date date, int line) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index 78695eb8f2b..999dd32e094 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -132,7 +132,7 @@ public class ComponentActionTest { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); init(); - verifySuccess(project.getDbKey()); + verifySuccess(project.getKey()); } @Test @@ -141,7 +141,7 @@ public class ComponentActionTest { userSession.logIn().setSystemAdministrator(); init(); - verifySuccess(project.getDbKey()); + verifySuccess(project.getKey()); } @Test @@ -150,7 +150,7 @@ public class ComponentActionTest { userSession.addProjectPermission(UserRole.USER, project); init(); - executeAndVerify(project.getDbKey(), "return_component_info_when_anonymous_no_snapshot.json"); + executeAndVerify(project.getKey(), "return_component_info_when_anonymous_no_snapshot.json"); } @Test @@ -162,7 +162,7 @@ public class ComponentActionTest { userSession.logIn(user).addProjectPermission(UserRole.USER, project); init(); - executeAndVerify(project.getDbKey(), "return_component_info_with_favourite.json"); + executeAndVerify(project.getKey(), "return_component_info_with_favourite.json"); } @Test @@ -211,7 +211,7 @@ public class ComponentActionTest { .getInput(); assertJson(json).isSimilarTo("{" + - " \"key\": \"" + subportfolio.getDbKey() + "\"," + + " \"key\": \"" + subportfolio.getKey() + "\"," + " \"isFavorite\": true," + " \"id\": \"" + subportfolio.uuid() + "\"," + " \"name\": \"" + subportfolio.name() + "\"" + @@ -238,7 +238,7 @@ public class ComponentActionTest { .getInput(); assertJson(json).isSimilarTo("{" + - " \"key\": \"" + portfolio.getDbKey() + "\"," + + " \"key\": \"" + portfolio.getKey() + "\"," + " \"isFavorite\": true," + " \"id\": \"" + portfolio.uuid() + "\"," + " \"name\": \"" + portfolio.name() + "\"" + @@ -269,13 +269,13 @@ public class ComponentActionTest { init(); // access to all projects (project11, project12) - String json = execute(application1.getDbKey()); + String json = execute(application1.getKey()); assertJson(json).isSimilarTo("{" + "\"canBrowseAllChildProjects\":true" + "}"); // access to some projects (project11) - json = execute(application2.getDbKey()); + json = execute(application2.getKey()); assertJson(json).isSimilarTo("{" + "\"canBrowseAllChildProjects\":false" + "}"); @@ -290,13 +290,13 @@ public class ComponentActionTest { userSession.addProjectPermission(UserRole.USER, project); init(); - executeAndVerify(project.getDbKey(), "return_component_info_when_snapshot.json"); + executeAndVerify(project.getKey(), "return_component_info_when_snapshot.json"); } @Test public void return_component_info_when_file_on_master() { db.qualityGates().createDefaultQualityGate(); - ComponentDto main = componentDbTester.insertPrivateProject(p -> p.setName("Sample").setDbKey("sample")); + ComponentDto main = componentDbTester.insertPrivateProject(p -> p.setName("Sample").setKey("sample")); userSession.addProjectPermission(UserRole.USER, main); init(); @@ -305,15 +305,15 @@ public class ComponentActionTest { ComponentDto fileDto = componentDbTester.insertComponent(newFileDto(main, dirDto) .setUuid("abcd") .setName("Main.xoo") - .setDbKey("sample:src/Main.xoo")); + .setKey("sample:src/Main.xoo")); - executeAndVerify(fileDto.getDbKey(), "return_component_info_when_file_on_master.json"); + executeAndVerify(fileDto.getKey(), "return_component_info_when_file_on_master.json"); } @Test public void return_component_info_when_file_on_branch() { db.qualityGates().createDefaultQualityGate(); - ComponentDto project = componentDbTester.insertPrivateProject(p -> p.setName("Sample").setDbKey("sample")); + ComponentDto project = componentDbTester.insertPrivateProject(p -> p.setName("Sample").setKey("sample")); ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1")); userSession.addProjectPermission(UserRole.USER, project); init(); @@ -363,12 +363,12 @@ public class ComponentActionTest { userSession.addProjectPermission(UserRole.USER, project); init(); - executeAndVerify(project.getDbKey(), "return_quality_profiles.json"); + executeAndVerify(project.getKey(), "return_quality_profiles.json"); db.getDbClient().qualityProfileDao().deleteOrgQProfilesByUuids(db.getSession(), ImmutableSet.of(qp1.getKee(), qp2.getKee())); db.commit(); - executeAndVerify(project.getDbKey(), "return_deleted_quality_profiles.json"); + executeAndVerify(project.getKey(), "return_deleted_quality_profiles.json"); } @Test @@ -377,7 +377,7 @@ public class ComponentActionTest { userSession.addProjectPermission(UserRole.USER, project); init(); - executeAndVerify(project.getDbKey(), "return_empty_quality_profiles_when_no_measure.json"); + executeAndVerify(project.getKey(), "return_empty_quality_profiles_when_no_measure.json"); } @Test @@ -418,7 +418,7 @@ public class ComponentActionTest { userSession.addProjectPermission(UserRole.USER, project); init(); - executeAndVerify(project.getDbKey(), "return_default_quality_gate.json"); + executeAndVerify(project.getKey(), "return_default_quality_gate.json"); } @Test @@ -427,7 +427,7 @@ public class ComponentActionTest { userSession.anonymous().addProjectPermission(UserRole.USER, project); init(createPages()); - executeAndVerify(project.getDbKey(), "return_extensions.json"); + executeAndVerify(project.getKey(), "return_extensions.json"); } @Test @@ -446,7 +446,7 @@ public class ComponentActionTest { init(page); String result = ws.newRequest() - .setParam(PARAM_COMPONENT, application.getDbKey()) + .setParam(PARAM_COMPONENT, application.getKey()) .execute().getInput(); assertThat(result).contains("my_plugin/app_page"); @@ -460,7 +460,7 @@ public class ComponentActionTest { .addProjectPermission(UserRole.ADMIN, project); init(createPages()); - executeAndVerify(project.getDbKey(), "return_extensions_for_admin.json"); + executeAndVerify(project.getKey(), "return_extensions_for_admin.json"); } @Test @@ -484,7 +484,7 @@ public class ComponentActionTest { .build(); init(page1, page2); - executeAndVerify(project.getDbKey(), "return_configuration_for_admin.json"); + executeAndVerify(project.getKey(), "return_configuration_for_admin.json"); } @Test @@ -505,7 +505,7 @@ public class ComponentActionTest { .thenReturn(projectResourceType); init(); - executeAndVerify(project.getDbKey(), "return_configuration_with_all_properties.json"); + executeAndVerify(project.getKey(), "return_configuration_with_all_properties.json"); } @Test @@ -516,7 +516,7 @@ public class ComponentActionTest { .addPermission(ADMINISTER_QUALITY_PROFILES); init(); - executeAndVerify(project.getDbKey(), "return_configuration_for_quality_profile_admin.json"); + executeAndVerify(project.getKey(), "return_configuration_for_quality_profile_admin.json"); } @Test @@ -527,7 +527,7 @@ public class ComponentActionTest { .addPermission(ADMINISTER_QUALITY_GATES); init(); - executeAndVerify(project.getDbKey(), "return_configuration_for_quality_gate_admin.json"); + executeAndVerify(project.getKey(), "return_configuration_for_quality_gate_admin.json"); } @Test @@ -538,7 +538,7 @@ public class ComponentActionTest { userSessionRule.addProjectPermission(UserRole.USER, project); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - String json = execute(project.getDbKey()); + String json = execute(project.getKey()); assertJson(json).isSimilarTo("{\n" + " \"configuration\": {\n" + @@ -566,7 +566,7 @@ public class ComponentActionTest { userSessionRule.addProjectPermission(UserRole.USER, project); userSessionRule.addProjectPermission(UserRole.ADMIN, project); - String json = execute(project.getDbKey()); + String json = execute(project.getKey()); assertJson(json).isSimilarTo("{\n" + " \"configuration\": {\n" + @@ -592,7 +592,7 @@ public class ComponentActionTest { init(); userSessionRule.addProjectPermission(UserRole.USER, project); - String json = execute(project.getDbKey()); + String json = execute(project.getKey()); assertThat(json).doesNotContain("\"configuration\""); } @@ -600,15 +600,15 @@ public class ComponentActionTest { @Test public void return_bread_crumbs_on_several_levels() { ComponentDto project = insertProject(); - ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap")); + ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setKey("palap").setName("Palap")); ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo")); ComponentDto file = componentDbTester.insertComponent(newFileDto(directory, directory, "cdef").setName("Source.xoo") - .setDbKey("palap:src/main/xoo/Source.xoo") + .setKey("palap:src/main/xoo/Source.xoo") .setPath(directory.path())); userSession.addProjectPermission(UserRole.USER, project); init(); - executeAndVerify(file.getDbKey(), "return_bread_crumbs_on_several_levels.json"); + executeAndVerify(file.getKey(), "return_bread_crumbs_on_several_levels.json"); } @Test @@ -617,7 +617,7 @@ public class ComponentActionTest { userSession.addProjectPermission(UserRole.ADMIN, project); init(createPages()); - execute(project.getDbKey()); + execute(project.getKey()); } @Test @@ -629,7 +629,7 @@ public class ComponentActionTest { userSession.logIn() .addProjectPermission(UserRole.ADMIN, project) .addPermission(GlobalPermission.ADMINISTER); - assertJson(execute(project.getDbKey())).isSimilarTo("{\"visibility\": \"private\"}"); + assertJson(execute(project.getKey())).isSimilarTo("{\"visibility\": \"private\"}"); } @Test @@ -641,7 +641,7 @@ public class ComponentActionTest { userSession.logIn() .addProjectPermission(UserRole.ADMIN, project) .addPermission(GlobalPermission.ADMINISTER); - assertJson(execute(project.getDbKey())).isSimilarTo("{\"visibility\": \"public\"}"); + assertJson(execute(project.getKey())).isSimilarTo("{\"visibility\": \"public\"}"); } @Test @@ -653,12 +653,12 @@ public class ComponentActionTest { userSession.logIn() .addProjectPermission(UserRole.ADMIN, project) .addPermission(GlobalPermission.ADMINISTER); - assertJson(execute(project.getDbKey())).isSimilarTo("{\"configuration\": {\"canApplyPermissionTemplate\": true}}"); + assertJson(execute(project.getKey())).isSimilarTo("{\"configuration\": {\"canApplyPermissionTemplate\": true}}"); userSession.logIn() .addProjectPermission(UserRole.ADMIN, project); - assertJson(execute(project.getDbKey())).isSimilarTo("{\"configuration\": {\"canApplyPermissionTemplate\": false}}"); + assertJson(execute(project.getKey())).isSimilarTo("{\"configuration\": {\"canApplyPermissionTemplate\": false}}"); } @Test @@ -668,7 +668,7 @@ public class ComponentActionTest { init(createPages()); userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - assertJson(execute(project.getDbKey())).isSimilarTo("{\"configuration\": {\"canUpdateProjectVisibilityToPrivate\": true}}"); + assertJson(execute(project.getKey())).isSimilarTo("{\"configuration\": {\"canUpdateProjectVisibilityToPrivate\": true}}"); } @Test @@ -696,7 +696,7 @@ public class ComponentActionTest { init(); userSession.logIn(); - String projectDbKey = project.getDbKey(); + String projectDbKey = project.getKey(); assertThatThrownBy(() -> execute(projectDbKey)) .isInstanceOf(ForbiddenException.class); } @@ -705,7 +705,7 @@ public class ComponentActionTest { public void test_example_response() { init(createPages()); ComponentDto project = newPrivateProjectDto("ABCD") - .setDbKey("org.codehaus.sonar:sonar") + .setKey("org.codehaus.sonar:sonar") .setName("Sonarqube") .setDescription("Open source platform for continuous inspection of code quality"); componentDbTester.insertPrivateProject(project); @@ -727,7 +727,7 @@ public class ComponentActionTest { .addProjectPermission(UserRole.USER, project) .addProjectPermission(UserRole.ADMIN, project); - String result = execute(project.getDbKey()); + String result = execute(project.getKey()); assertJson(result).ignoreFields("snapshotDate", "canBrowseAllChildProjects", "key", "qualityGate.key").isSimilarTo(ws.getDef().responseExampleAsString()); } @@ -756,7 +756,7 @@ public class ComponentActionTest { @Test public void fail_on_module_key_as_param() { ComponentDto project = insertProject(); - ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap")); + ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setKey("palap").setName("Palap")); init(); assertThatThrownBy(() -> execute(module.getKey())) @@ -766,18 +766,18 @@ public class ComponentActionTest { @Test public void fail_on_directory_key_as_param() { ComponentDto project = insertProject(); - ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap")); + ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setKey("palap").setName("Palap")); ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo")); userSession.addProjectPermission(UserRole.USER, project); init(); - assertThatThrownBy(() -> execute(directory.getDbKey())) + assertThatThrownBy(() -> execute(directory.getKey())) .isInstanceOf(BadRequestException.class); } private ComponentDto insertProject() { db.qualityGates().createDefaultQualityGate(); - return db.components().insertPrivateProject("abcd", p -> p.setDbKey("polop") + return db.components().insertPrivateProject("abcd", p -> p.setKey("polop") .setName("Polop") .setDescription("test project") .setQualifier(Qualifiers.PROJECT) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java index 8707a53595b..5faba1a34bc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java @@ -205,7 +205,7 @@ public class CurrentActionTest { @Test public void json_example() { - ComponentDto componentDto = db.components().insertPrivateProject(u -> u.setUuid("UUID-of-the-death-star").setDbKey("death-star-key")); + ComponentDto componentDto = db.components().insertPrivateProject(u -> u.setUuid("UUID-of-the-death-star").setKey("death-star-key")); UserDto obiwan = db.users().insertUser(user -> user .setLogin("obiwan.kenobi") .setName("Obiwan Kenobi") diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java index 7bdfa6ebc00..df5e0bf9c81 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java @@ -68,7 +68,7 @@ public class SearchActionTest { @Test public void search_json_example() { - ComponentDto project1 = db.components().insertPublicProject(p -> p.setDbKey("project-1").setName("Project 1")); + ComponentDto project1 = db.components().insertPublicProject(p -> p.setKey("project-1").setName("Project 1")); UserDto user1 = db.users().insertUser(u -> u.setLogin("grace.hopper")); UserDto user2 = db.users().insertUser(u -> u.setLogin("ada.lovelace")); db.users().insertToken(user1, t -> t.setName("Project scan on Travis").setCreatedAt(1448523067221L)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/CreateActionTest.java index f139d6c9780..3ac6ec2bb19 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/CreateActionTest.java @@ -96,7 +96,7 @@ public class CreateActionTest { @Test public void create_a_webhook_with_400_length_project_key() { String longProjectKey = generateStringWithLength(400); - ComponentDto project = componentDbTester.insertPrivateProject(componentDto -> componentDto.setDbKey(longProjectKey)); + ComponentDto project = componentDbTester.insertPrivateProject(componentDto -> componentDto.setKey(longProjectKey)); userSession.logIn().addProjectPermission(ADMIN, project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java index 83a00865dfd..6215f1416a2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java @@ -65,8 +65,8 @@ public class WebhookDeliveriesActionTest { ComponentFinder componentFinder = TestComponentFinder.from(db); WebhookDeliveriesAction underTest = new WebhookDeliveriesAction(dbClient, userSession, componentFinder); ws = new WsActionTester(underTest); - project = db.components().insertPrivateProject(c -> c.setDbKey("my-project")); - otherProject = db.components().insertPrivateProject(c -> c.setDbKey("other-project")); + project = db.components().insertPrivateProject(c -> c.setKey("my-project")); + otherProject = db.components().insertPrivateProject(c -> c.setKey("other-project")); } @Test @@ -89,7 +89,7 @@ public class WebhookDeliveriesActionTest { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); Webhooks.DeliveriesWsResponse response = ws.newRequest() - .setParam("componentKey", project.getDbKey()) + .setParam("componentKey", project.getKey()) .executeProtobuf(Webhooks.DeliveriesWsResponse.class); assertThat(response.getDeliveriesCount()).isZero(); @@ -134,7 +134,7 @@ public class WebhookDeliveriesActionTest { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); String json = ws.newRequest() - .setParam("componentKey", project.getDbKey()) + .setParam("componentKey", project.getKey()) .execute() .getInput(); @@ -184,10 +184,10 @@ public class WebhookDeliveriesActionTest { .containsOnly(dto1.getUuid(), dto2.getUuid(), dto4.getUuid(), dto5.getUuid()); assertThat(response.getDeliveriesList()).extracting(Webhooks.Delivery::getId, Webhooks.Delivery::getComponentKey) .containsOnly( - tuple(dto1.getUuid(), project.getDbKey()), - tuple(dto2.getUuid(), project.getDbKey()), - tuple(dto4.getUuid(), otherProject.getDbKey()), - tuple(dto5.getUuid(), otherProject.getDbKey())); + tuple(dto1.getUuid(), project.getKey()), + tuple(dto2.getUuid(), project.getKey()), + tuple(dto4.getUuid(), otherProject.getKey()), + tuple(dto5.getUuid(), otherProject.getKey())); } @Test @@ -256,7 +256,7 @@ public class WebhookDeliveriesActionTest { userSession.logIn().addProjectPermission(UserRole.USER, project); TestRequest request = ws.newRequest() - .setParam("componentKey", project.getDbKey()); + .setParam("componentKey", project.getKey()); assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); @@ -282,7 +282,7 @@ public class WebhookDeliveriesActionTest { userSession.logIn(); TestRequest request = ws.newRequest() - .setParam("componentKey", project.getDbKey()) + .setParam("componentKey", project.getKey()) .setParam("ceTaskId", "t1"); assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) @@ -294,7 +294,7 @@ public class WebhookDeliveriesActionTest { userSession.logIn(); TestRequest request = ws.newRequest() - .setParam("componentKey", project.getDbKey()) + .setParam("componentKey", project.getKey()) .setParam("webhook", "wh-uuid"); assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java index fe2986a01b1..53e6d7c42c0 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java @@ -61,7 +61,7 @@ public class WebhookDeliveryActionTest { ComponentFinder componentFinder = TestComponentFinder.from(db); WebhookDeliveryAction underTest = new WebhookDeliveryAction(dbClient, userSession, componentFinder); ws = new WsActionTester(underTest); - project = db.components().insertPrivateProject(c -> c.setDbKey("my-project")); + project = db.components().insertPrivateProject(c -> c.setKey("my-project")); } @Test |