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));
}
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));
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));
*/
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 {
* @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));
+ }
+ }
}
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()));
}
}
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())
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);
*/
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
private final Status status;
private final String name;
private final String shortName;
- private final String dbKey;
private final String key;
private final String uuid;
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;
return uuid;
}
- @Override
- public String getDbKey() {
- return dbKey;
- }
-
@Override
public String getKey() {
return key;
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";
private ProjectAttributes projectAttributes;
private ReportAttributes reportAttributes;
private String uuid;
- private String dbKey;
private String key;
private String name;
private String shortName;
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;
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);
"type=" + type +
", status=" + status +
", name='" + name + '\'' +
- ", dbKey='" + dbKey + '\'' +
", key='" + key + '\'' +
", uuid='" + uuid + '\'' +
", description='" + description + '\'' +
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>
public ComponentTreeBuilder(
ComponentKeyGenerator keyGenerator,
- ComponentKeyGenerator publicKeyGenerator,
UnaryOperator<String> uuidSupplier,
Function<Integer, ScannerReport.Component> scannerComponentSupplier,
Project project,
ProjectAttributes projectAttributes) {
this.keyGenerator = keyGenerator;
- this.publicKeyGenerator = publicKeyGenerator;
this.uuidSupplier = uuidSupplier;
this.scannerComponentSupplier = scannerComponentSupplier;
this.project = project;
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())
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()))
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))
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())
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));
- }
}
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());
}
}
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));
}
}
@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());
}
}
}
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());
}
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());
}
}
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());
}
}
VisitException.rethrowOrWrap(
e,
"Visit of Component {key=%s,type=%s} failed",
- component.getDbKey(), component.getType());
+ component.getKey(), component.getType());
}
}
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:
return "";
}
if (duplicate instanceof InProjectDuplicate) {
- return ((InProjectDuplicate) duplicate).getFile().getDbKey();
+ return ((InProjectDuplicate) duplicate).getFile().getKey();
}
if (duplicate instanceof CrossProjectDuplicate) {
return ((CrossProjectDuplicate) duplicate).getFileKey();
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();
}
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) {
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);
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++;
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);
}
}
return Optional.empty();
}
- return Optional.ofNullable(originalFiles.get(file.getDbKey()));
+ return Optional.ofNullable(originalFiles.get(file.getKey()));
}
}
}
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);
}
}
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 -> {
}
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();
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());
}
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;
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());
}
}
@CheckForNull
- public String getTargetBranchComponentUuid(String dbKey) {
+ public String getTargetBranchComponentUuid(String key) {
lazyInit();
- String cleanComponentKey = removeBranchAndPullRequestFromKey(dbKey);
- return targetBranchComponentsUuidsByKey.get(cleanComponentKey);
+ return targetBranchComponentsUuidsByKey.get(key);
}
}
}
public Input<DefaultIssue> create(Component component) {
- String referenceBranchComponentUuid = referenceBranchComponentUuids.getComponentUuid(component.getDbKey());
+ String referenceBranchComponentUuid = referenceBranchComponentUuids.getComponentUuid(component.getKey());
return new ReferenceLazyInput(component.getType(), referenceBranchComponentUuid);
}
}
public Input<DefaultIssue> createForSourceBranch(Component component) {
- String sourceBranchComponentUuid = sourceBranchComponentUuids.getSourceBranchComponentUuid(component.getDbKey());
+ String sourceBranchComponentUuid = sourceBranchComponentUuids.getSourceBranchComponentUuid(component.getKey());
return new SourceBranchLazyInput(component.getType(), sourceBranchComponentUuid);
}
}
public Input<DefaultIssue> createForTargetBranch(Component component) {
- String targetBranchComponentUuid = targetBranchComponentUuids.getTargetBranchComponentUuid(component.getDbKey());
+ String targetBranchComponentUuid = targetBranchComponentUuids.getTargetBranchComponentUuid(component.getKey());
return new TargetLazyInput(component.getType(), targetBranchComponentUuid);
}
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);
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);
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());
}
}
if (isReferenceBranch()) {
- var referencedBranchComponentUuid = newCodeReferenceBranchComponentUuids.getComponentUuid(file.getDbKey());
+ var referencedBranchComponentUuid = newCodeReferenceBranchComponentUuids.getComponentUuid(file.getKey());
if (referencedBranchComponentUuid != null) {
return Optional.of(referencedBranchComponentUuid);
}
// 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();
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);
}
}
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));
}
@CheckForNull
private String getReferenceComponentUuid(Component component) {
if (analysisMetadataHolder.isPullRequest()) {
- return referenceBranchComponentUuids.getComponentUuid(component.getDbKey());
+ return referenceBranchComponentUuids.getComponentUuid(component.getKey());
} else {
return component.getUuid();
}
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);
}
}
@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);
}
}
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());
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);
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);
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;
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
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(),
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())
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;
}
}
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);
}
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();
}
* 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()));
}
// 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());
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);
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);
}
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()));
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));
* 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)
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()) ||
}
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);
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();
}
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;
}
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);
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);
@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();
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;
* 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() {
@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))
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");
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");
}
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);
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());
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);
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);
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);
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())
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);
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);
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());
}
});
}
}
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));
}
}
private static CallRecord viewsCallRecord(Component component, String method) {
- return CallRecord.viewsCallRecord(method, component.getDbKey());
+ return CallRecord.viewsCallRecord(method, component.getKey());
}
}
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");
}
assertThatThrownBy(() -> {
builder(Component.Type.DIRECTORY)
.setName("DIR")
- .setDbKey(KEY)
+ .setKey(KEY)
.setUuid(UUID)
.setReportAttributes(ReportAttributes.newBuilder(1).build())
.build();
@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);
}
@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);
}
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())
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);
}
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());
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 = "";
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() {
.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);
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();
}
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");
}
// 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");
}
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");
}
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");
}
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
.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");
}
.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");
}
.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");
}
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) {
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;
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());
@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());
@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());
@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());
@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());
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");
}
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();
}
}
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));
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
}
private static CallRecord viewsCallRecord(String methodName, Component component) {
- return CallRecord.viewsCallRecord(methodName, component.getDbKey());
+ return CallRecord.viewsCallRecord(methodName, component.getKey());
}
}
}
private static CallRecord viewsCallRecord(String methodName, Component component) {
- return CallRecord.viewsCallRecord(methodName, component.getDbKey());
+ return CallRecord.viewsCallRecord(methodName, component.getKey());
}
}
super(maxDepth, order, new SimpleStackElementFactory<Integer>() {
@Override
public Integer createForAny(Component component) {
- return Integer.valueOf(component.getDbKey());
+ return Integer.valueOf(component.getKey());
}
});
}
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);
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();
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();
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();
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();
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();
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();
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();
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();
private ComponentDto newComponentDto(String uuid) {
return ComponentTesting.newFileDto(project)
- .setDbKey("key_" + uuid)
+ .setKey("key_" + uuid)
.setUuid(uuid)
.setPath("path_" + uuid);
}
}
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);
}
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);
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();
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,
@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));
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()));
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));
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()));
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);
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();
}
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
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();
}
}
private static final String BRANCH_KEY = "branch1";
private static final String PR_KEY = "pr1";
- @org.junit.Rule
+ @Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
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();
}
when(branch.getName()).thenReturn("prBranch");
when(branch.getTargetBranchName()).thenReturn(BRANCH_KEY);
- assertThat(underTest.getTargetBranchComponentUuid(pr1File.getDbKey())).isNull();
+ assertThat(underTest.getTargetBranchComponentUuid(pr1File.getKey())).isNull();
}
@Test
when(branch.getName()).thenReturn("prBranch");
when(branch.getTargetBranchName()).thenReturn(BRANCH_KEY);
- assertThat(underTest.getTargetBranchComponentUuid(pr1File.getDbKey())).isNull();
+ assertThat(underTest.getTargetBranchComponentUuid(pr1File.getKey())).isNull();
}
}
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);
@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);
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);
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);
@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);
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);
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);
@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);
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
@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);
}
}
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();
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();
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();
assertThat(underTest.hasLineHashesWithSignificantCode(component)).isFalse();
verify(analysisMetadataHolder).isPullRequest();
- verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey());
+ verify(referenceBranchComponentUuids).getComponentUuid(component.getKey());
}
@Test
assertThat(underTest.hasLineHashesWithSignificantCode(component)).isFalse();
verify(analysisMetadataHolder).isPullRequest();
- verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey());
+ verify(referenceBranchComponentUuids).getComponentUuid(component.getKey());
}
@Test
assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();
verify(analysisMetadataHolder).isPullRequest();
- verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey());
+ verify(referenceBranchComponentUuids).getComponentUuid(component.getKey());
}
@Test
@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
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");
}
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));
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
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))
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
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
@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));
@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));
@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));
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));
}
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);
}
}
- 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);
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) {
.build()),
singletonList(
new Block.Builder()
- .setResourceId(otherFile.getDbKey())
+ .setResourceId(otherFile.getKey())
.setBlockHash(new ByteArray(hash))
.setIndexInFile(duplicate.getIndexInFile())
.setLines(duplicate.getStartLine(), duplicate.getEndLine())
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())
}
private ComponentDto createProject(String projectKey) {
- ComponentDto project = ComponentTesting.newPrivateProjectDto().setDbKey(projectKey);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto().setKey(projectKey);
return dbTester.components().insertComponent(project);
}
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();
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
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());
}
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 + ")");
}
ComponentDto otherProject = db.components().insertPublicProject();
reportReader.setMetadata(
ScannerReport.Metadata.newBuilder()
- .setProjectKey(otherProject.getDbKey())
+ .setProjectKey(otherProject.getKey())
.build());
try {
ComponentDto otherProject = db.components().insertPublicProject();
reportReader.setMetadata(
ScannerReport.Metadata.newBuilder()
- .setProjectKey(otherProject.getDbKey())
+ .setProjectKey(otherProject.getKey())
.setAnalysisDate(ANALYSIS_DATE)
.build());
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());
}
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));
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;
}
.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");
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;
}
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;
}
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);
}
@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();
@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);
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();
@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);
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;
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());
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());
@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")
.setShortName("dir")
.addChildren(file)
.build();
- Component treeRoot = asTreeRoot(project)
+ Component treeRoot = asTreeRoot(branch)
.addChildren(directory)
.build();
treeRootHolder.setRoot(treeRoot);
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();
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);
}
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");
}
@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();
@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();
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")
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();
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();
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();
}
@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")
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();
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());
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());
@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")
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();
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());
}
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());
.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")
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();
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());
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());
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());
}
private ReportComponent createSampleProjectComponentTree(ComponentDto project) {
- return createSampleProjectComponentTree(project.uuid(), project.getDbKey());
+ return createSampleProjectComponentTree(project.uuid(), project.getKey());
}
private ReportComponent createSampleProjectComponentTree(String projectUuid, String projectKey) {
}
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() {
}
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() {
@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()));
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)];
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;
}
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)];
@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))
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;
}
@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();
@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();
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();
@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())
@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();
@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();
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);
// 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);
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)
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(
.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) {
private ComponentDto newViewDto() {
return ComponentTesting.newPortfolio(VIEW_UUID)
- .setDbKey(VIEW_KEY)
+ .setKey(VIEW_KEY)
.setName(VIEW_NAME);
}
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() + ".");
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() + ".");
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() + ".");
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() + ".");
// no id yet
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.PROJECT)
- .setDbKey("the_project")
+ .setKey("the_project")
.setName("The Project")
.setDescription("The project description")
.setEnabled(true)
.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;
// no id yet
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.MODULE)
- .setDbKey("the_module")
+ .setKey("the_module")
.setName("The Module")
.setDescription("description of module")
.setEnabled(true)
.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)
.setEnabled(true)
.setModuleUuid(MODULE_UUID)
.setModuleUuidPath("." + PROJECT_UUID + ".MODULE_UUID.")
- .setProjectUuid(PROJECT_UUID);
+ .setBranchUuid(PROJECT_UUID);
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
// no id yet
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.PROJECT)
- .setDbKey("the_project")
+ .setKey("the_project")
.setName("The Project")
.setDescription("The project description")
.setEnabled(true)
.setRootUuid(PROJECT_UUID)
.setModuleUuid(null)
.setModuleUuidPath("." + PROJECT_UUID + ".")
- .setProjectUuid(PROJECT_UUID);
+ .setBranchUuid(PROJECT_UUID);
@Rule
public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
// no id yet
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.PROJECT)
- .setDbKey("the_project")
+ .setKey("the_project")
.setName("The Project")
.setDescription("The project description")
.setEnabled(true)
.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;
// no id yet
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.MODULE)
- .setDbKey("the_module")
+ .setKey("the_module")
.setName("The Module")
.setDescription("description of module")
.setEnabled(true)
.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;
// no id yet
.setScope(Scopes.FILE)
.setQualifier(Qualifiers.FILE)
- .setDbKey("the_file")
+ .setKey("the_file")
.setName("The File")
.setUuid(FILE_UUID)
.setRootUuid(MODULE_UUID)
.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);
}
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);
}
// no id yet
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.PROJECT)
- .setDbKey("the_project")
+ .setKey("the_project")
.setName("The Project")
.setDescription("The project description")
.setEnabled(true)
.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"),
.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);
// no id yet
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.PROJECT)
- .setDbKey("the_project")
+ .setKey("the_project")
.setName("The Project")
.setDescription("The project description")
.setEnabled(true)
.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);
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);
.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"),
.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();
@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());
}
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")
@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;
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;
}
@Override
- public String getDbKey() {
+ public String getKey() {
if (key == null) {
throw new UnsupportedOperationException(String.format("Component key of ref '%d' has not be fed yet", this.reportAttributes.getRef()));
}
return key;
}
- @Override
- public String getKey() {
- if (publicKey == null) {
- throw new UnsupportedOperationException(String.format("Component key of ref '%d' has not be fed yet", this.reportAttributes.getRef()));
- }
- return publicKey;
- }
-
@Override
public String getName() {
return this.name;
}
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) {
private Status status;
private String uuid;
private String key;
- private String publicKey;
private String name;
private String shortName;
private String projectVersion;
return this;
}
- public Builder setPublicKey(String publicKey) {
- this.publicKey = requireNonNull(publicKey);
- return this;
- }
-
public Builder setProjectVersion(@Nullable String s) {
checkProjectVersion(s);
this.projectVersion = s;
}
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
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();
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
}
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();
- }
- }
-
}
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);
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));
}
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) {
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;
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));
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);
}
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;
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;
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;
}
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)));
}
/**
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) {
}
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;
}
/**
}
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) {
}
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);
}
}
/**
- * 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);
}
/**
* 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) {
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) {
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;
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);
* - 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 !
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
*/
/**
* 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;
}
}
/**
- * Use {@link #projectUuid()}, {@link #moduleUuid()} or {@link #moduleUuidPath()}
+ * Use {@link #branchUuid()}, {@link #moduleUuid()} or {@link #moduleUuidPath()}
*/
@Deprecated
public String getRootUuid() {
.append("kee", kee)
.append("scope", scope)
.append("qualifier", qualifier)
- .append("projectUuid", projectUuid)
+ .append("branchUuid", branchUuid)
.append("moduleUuid", moduleUuid)
.append("moduleUuidPath", moduleUuidPath)
.append("rootUuid", rootUuid)
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;
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);
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);
* <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
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);
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);
return new ComponentUpdateDto()
.setUuid(from.uuid())
.setBChanged(false)
- .setBKey(from.getDbKey())
+ .setBKey(from.getKey())
.setBCopyComponentUuid(from.getCopyComponentUuid())
.setBDescription(from.description())
.setBEnabled(from.isEnabled())
--- /dev/null
+/*
+ * 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.db.component;
+
+public class UuidWithBranchUuidDto {
+
+ private String uuid;
+ private String branchUuid;
+
+ public String getBranchUuid() {
+ return branchUuid;
+ }
+
+ public UuidWithBranchUuidDto setBranchUuid(String branchUuid) {
+ this.branchUuid = branchUuid;
+ return this;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public UuidWithBranchUuidDto setUuid(String uuid) {
+ this.uuid = uuid;
+ return this;
+ }
+}
+++ /dev/null
-/*
- * 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.db.component;
-
-public class UuidWithProjectUuidDto {
-
- private String uuid;
- private String projectUuid;
-
- public String getProjectUuid() {
- return projectUuid;
- }
-
- public UuidWithProjectUuidDto setProjectUuid(String projectUuid) {
- this.projectUuid = projectUuid;
- return this;
- }
-
- public String getUuid() {
- return uuid;
- }
-
- public UuidWithProjectUuidDto setUuid(String uuid) {
- this.uuid = uuid;
- return this;
- }
-}
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) {
}
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();
}
public IssueDto setProject(ComponentDto project) {
- this.projectKey = project.getDbKey();
+ this.projectKey = project.getKey();
this.projectUuid = project.uuid();
return this;
}
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) {
}
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))
*/
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);
@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);
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}
<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,
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">
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>
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">
</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
<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
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
</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>
<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}
</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}
</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}
<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>
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 '\'}
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}
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">
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">
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>
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')
kee,
uuid,
uuid_path,
- project_uuid,
+ branch_uuid,
module_uuid,
module_uuid_path,
main_branch_project_uuid,
#{kee,jdbcType=VARCHAR},
#{uuid,jdbcType=VARCHAR},
#{uuidPath,jdbcType=VARCHAR},
- #{projectUuid,jdbcType=VARCHAR},
+ #{branchUuid,jdbcType=VARCHAR},
#{moduleUuid,jdbcType=VARCHAR},
#{moduleUuidPath,jdbcType=VARCHAR},
#{mainBranchProjectUuid, jdbcType=VARCHAR},
b_path = null,
b_qualifier = null
where
- project_uuid = #{projectUuid,jdbcType=VARCHAR} and
+ branch_uuid = #{branchUuid,jdbcType=VARCHAR} and
b_changed = ${_true}
</update>
<!-- 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>
update components set
private = #{isPrivate,jdbcType=BOOLEAN}
where
- project_uuid = #{projectUuid,jdbcType=VARCHAR}
+ branch_uuid = #{branchUuid,jdbcType=VARCHAR}
and private <> #{isPrivate,jdbcType=BOOLEAN}
</update>
<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}
<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">
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
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
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 (
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">
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>
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">
<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">
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>
"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),
"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,
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();
}
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();
}
@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());
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);
@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();
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();
}
*/
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;
@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();
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");
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));
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");
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();
}
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();
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();
}
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
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();
}
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
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();
}
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
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();
}
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);
}
// 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())))
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(),
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();
}
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
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();
}
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
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);
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
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);
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);
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);
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);
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
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);
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);
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);
@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());
.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))
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(),
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);
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);
@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")
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
@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
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
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();
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();
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);
@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")
.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");
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();
- }
}
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);
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();
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");
}
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();
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
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());
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";
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";
}
private ComponentDto prefixDbKeyWithKey(ComponentDto componentDto, String key) {
- return componentDto.setDbKey(key + ":" + componentDto.getDbKey());
+ return componentDto.setKey(key + ":" + componentDto.getKey());
}
@Test
@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))
@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");
}
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"));
}
}
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);
})
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());
// 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))
// 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));
// 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
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);
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() {
.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));
}
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;
}
@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);
@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"));
@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));
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());
}
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);
}
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");
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");
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());
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());
@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);
@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()))
@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));
@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()))
.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()))
@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());
@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));
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() {
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"))
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())
}
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) {
@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);
}
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) {
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());
@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);
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();
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);
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);
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
.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()));
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();
@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());
@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);
@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);
}
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);
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)
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)
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 {
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)
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)
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)
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")
.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);
}
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)
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())
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())
}
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) {
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())
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())
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());
}
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++);
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))
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))
--- /dev/null
+/*
+ * 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());
+ }
+ }
+
+}
.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)
;
}
}
--- /dev/null
+/*
+ * 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");
+ }
+}
--- /dev/null
+/*
+ * 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");
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+
+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);
--- /dev/null
+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);
--- /dev/null
+
+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);
dbClient.componentDao().scrollForIndexing(dbSession, branchUuid, context -> {
ComponentDto dto = context.getResultObject();
bulkIndexer.add(toDocument(dto).toIndexRequest());
- remaining.remove(dto.projectUuid());
+ remaining.remove(dto.branchUuid());
});
}
return new ComponentDoc()
.setId(component.uuid())
.setName(component.name())
- .setKey(component.getDbKey())
- .setProjectUuid(component.projectUuid())
+ .setKey(component.getKey())
+ .setProjectUuid(component.branchUuid())
.setQualifier(component.qualifier());
}
}
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);
}
.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) {
.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());
}
}
@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);
}
}
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();
}
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) {
"c.module_uuid_path",
"c.path",
"c.scope",
- "c.project_uuid",
+ "c.branch_uuid",
"c.main_branch_project_uuid",
// column 21
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;
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);
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(","));
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) {
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();
}));
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;
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);
}
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);
}
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());
}
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");
.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();
}
}
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) {
@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));
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)
@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);
}
@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);
}
}
// 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);
}
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);
.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()));
*/
package org.sonar.server.user;
-import java.util.Arrays;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
.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);
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
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
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
TokenUserSession userSession = mockGlobalAnalysisTokenUserSession(user);
- assertThat(userSession.hasProjectUuidPermission(SCAN, project1.projectUuid())).isFalse();
+ assertThat(userSession.hasProjectUuidPermission(SCAN, project1.branchUuid())).isFalse();
assertThat(userSession.hasPermission(GlobalPermission.SCAN)).isTrue();
}
userTokenDto.setUserUuid("userUid");
userTokenDto.setProjectKey(componentDto.getKey());
userTokenDto.setProjectName(componentDto.name());
- userTokenDto.setProjectUuid(componentDto.projectUuid());
+ userTokenDto.setProjectUuid(componentDto.branchUuid());
return userTokenDto;
}
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);
}
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);
}
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());
.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;
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()))
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));
}
SuggestionQuery query1 = SuggestionQuery.builder()
.setQuery("bar")
.setQualifiers(singletonList(PROJECT))
- .setFavoriteKeys(of(project1.getDbKey()))
+ .setFavoriteKeys(of(project1.getKey()))
.build();
assertSearch(query1).isEmpty();
}
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));
}
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));
}
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(
@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());
.setId(componentDoc.uuid())
.setKey(componentDoc.getKey())
.setName(componentDoc.name())
- .setProjectUuid(componentDoc.projectUuid())
+ .setProjectUuid(componentDoc.branchUuid())
.setQualifier(componentDoc.qualifier());
}
}
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);
}
protected ComponentDto indexFile(ComponentDto project, String fileKey, String fileName) {
return index(
ComponentTesting.newFileDto(project)
- .setDbKey(fileKey)
+ .setKey(fileKey)
.setName(fileName));
}
@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()));
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,
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");
.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()))
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);
@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));
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();
@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);
@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),
@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()),
@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()),
@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")),
@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);
private static ProjectMeasuresDoc newDoc(ComponentDto project) {
return new ProjectMeasuresDoc()
.setId(project.uuid())
- .setKey(project.getDbKey())
+ .setKey(project.getKey())
.setName(project.name())
.setQualifier(project.qualifier());
}
@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");
@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");
@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");
@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");
@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");
@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");
}
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);
@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");
private static ProjectMeasuresDoc newDoc(ComponentDto project) {
return new ProjectMeasuresDoc()
.setId(project.uuid())
- .setKey(project.getDbKey())
+ .setKey(project.getKey())
.setName(project.name())
.setQualifier(project.qualifier());
}
when(dbClient.ceActivityDao()).thenReturn(ceActivityDao);
when(dbClient.componentDao()).thenReturn(componentDao);
ComponentDto componentDto = new ComponentDto();
- componentDto.setDbKey("key");
+ componentDto.setKey("key");
}
@Test
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;
IssueChangedEvent event = getIssueChangedEvent(projectKey, issuesInProject, issueChanges);
if (event != null) {
- persistEvent(event, entry.getValue().projectUuid());
+ persistEvent(event, entry.getValue().branchUuid());
}
}
}
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);
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);
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())))
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)
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");
}
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);
public abstract static class ComponentKey {
public abstract String getKey();
- public abstract String getDbKey();
-
public abstract Optional<String> getBranchName();
public abstract Optional<String> getPullRequestKey();
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
return key;
}
- @Override
- public String getDbKey() {
- return dbKey;
- }
-
@Override
public Optional<String> getBranchName() {
return Optional.empty();
return Optional.empty();
}
- @Override
- public ComponentKey getMainBranchComponentKey() {
- return this;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
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);
}
}
}
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;
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));
}
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));
}
}
- 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();
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)));
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;
.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())
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())
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());
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) {
.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();
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());
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));
}
.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);
}
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)
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));
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();
}
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());
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);
}
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()));
}
}
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() {
return blocks;
}
- DuplicationComparator duplicationComparator = new DuplicationComparator(component.uuid(), component.projectUuid());
+ DuplicationComparator duplicationComparator = new DuplicationComparator(component.uuid(), component.branchUuid());
try {
SMInputFactory inputFactory = initStax();
}
private static String convertToKey(String dbKey) {
- return new ComponentDto().setDbKey(dbKey).getKey();
+ return new ComponentDto().setKey(dbKey).getKey();
}
private static SMInputFactory initStax() {
}
private boolean sameProject(@Nullable ComponentDto otherDto) {
- return otherDto == null || StringUtils.equals(otherDto.projectUuid(), projectUuid);
+ return otherDto == null || StringUtils.equals(otherDto.branchUuid(), projectUuid);
}
}
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));
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();
*/
package org.sonar.server.hotspot.ws;
+import javax.annotation.Nullable;
import org.sonar.db.component.ComponentDto;
import org.sonarqube.ws.Hotspots;
// 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();
}
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;
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;
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;
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) {
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()));
}
}
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,
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() {
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;
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()));
}
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);
: 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() {
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());
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)) {
}
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);
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);
}
}
}
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);
}
}
}
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);
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);
ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyComponentUuid());
if (referenceComponent != null) {
- wsComponent.setRefKey(referenceComponent.getDbKey());
+ wsComponent.setRefKey(referenceComponent.getKey());
}
Measures.Measure.Builder measureBuilder = Measures.Measure.newBuilder();
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)
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());
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;
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()));
Map<String, ComponentDto> projectsByUuid) {
ComponentDto project = projectsByUuid.get(componentUuid);
notification
- .setProject(project.getDbKey())
+ .setProject(project.getKey())
.setProjectName(project.name());
}
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;
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);
}
*/
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;
@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);
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);
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())))
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());
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()));
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()
}
Supplier<Optional<Long>> periodDateSupplier = () -> dbClient.snapshotDao()
- .selectLastAnalysisByComponentUuid(dbSession, fileDto.projectUuid())
+ .selectLastAnalysisByComponentUuid(dbSession, fileDto.branchUuid())
.map(SnapshotDto::getPeriodDate);
Iterable<DbFileSources.Line> lineSources = lineSourcesOpt.get();
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);
!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();
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;
}
}
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());
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());
}
}
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);
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);
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"));
});
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);
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"));
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");
"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()
.setUuid(uuid)
.setUuidPath(uuid + ".")
.setRootUuid(uuid)
- .setProjectUuid(uuid)
+ .setBranchUuid(uuid)
.setScope(scope)
.setModuleUuid(moduleUuid)
- .setDbKey(key));
+ .setKey(key));
dbSession.commit();
try {
return new FileSourceDto()
.setUuid(Uuids.createFast())
.setFileUuid(file.uuid())
- .setProjectUuid(file.projectUuid())
+ .setProjectUuid(file.branchUuid())
.setDataHash("0263047cd758c68c27683625f072f010")
.setLineHashes(of("8d7b3d6b83c0a517eac07e1aac94b773"))
.setCreatedAt(System.currentTimeMillis())
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
assertThatThrownBy(() -> tester.newRequest()
- .setParam("project", project.getDbKey())
+ .setParam("project", project.getKey())
.setParam("branch", "branch1")
.execute())
.isInstanceOf(NotFoundException.class)
@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"));
userSession.logIn().addProjectPermission(USER, project);
String json = ws.newRequest()
- .setParam("project", project.getDbKey())
+ .setParam("project", project.getKey())
.execute()
.getInput();
@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"));
userSession.logIn().addProjectPermission(SCAN_EXECUTION, project);
String json = ws.newRequest()
- .setParam("project", project.getDbKey())
+ .setParam("project", project.getKey())
.execute()
.getInput();
userSession.logIn().addProjectPermission(USER, project);
ListWsResponse response = ws.newRequest()
- .setParam("project", project.getDbKey())
+ .setParam("project", project.getKey())
.executeProtobuf(ListWsResponse.class);
assertThat(response.getBranchesList())
userSession.logIn().addProjectPermission(USER, project);
ListWsResponse response = ws.newRequest()
- .setParam("project", project.getDbKey())
+ .setParam("project", project.getKey())
.executeProtobuf(ListWsResponse.class);
assertThat(response.getBranchesList())
userSession.logIn().addProjectPermission(USER, application);
ListWsResponse response = ws.newRequest()
- .setParam("project", application.getDbKey())
+ .setParam("project", application.getKey())
.executeProtobuf(ListWsResponse.class);
assertThat(response.getBranchesList())
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
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
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);
}
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);
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);
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));
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);
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);
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()))
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);
}
}
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;
}
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();
}
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);
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));
}
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));
}
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);
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);
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");
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);
@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);
userSession.logIn();
ComponentDto project = db.components().insertPrivateProject();
- String dbKey = project.getDbKey();
+ String dbKey = project.getKey();
assertThatThrownBy(() -> callByComponentKey(dbKey))
.isInstanceOf(ForbiddenException.class)
.hasMessage("Insufficient privileges");
@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);
}
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() {
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();
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();
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);
@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();
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
@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)
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));
@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
@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();
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();
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();
}
logInAsProjectAdministrator(project);
ProjectDto projectDto = componentDb.getProjectDto(project);
- String anotherProjectDbKey = anotherProject.getDbKey();
+ String anotherProjectDbKey = anotherProject.getKey();
assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto,
anotherProjectDbKey))
.isInstanceOf(IllegalArgumentException.class)
}
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) {
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());
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();
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();
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
@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()
userSession.logIn("john").addProjectPermission(USER, project);
String result = ws.newRequest()
- .setParam("component", file.getDbKey())
+ .setParam("component", file.getKey())
.execute()
.getInput();
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();
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();
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)
@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)));
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[] {}));
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();
}
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
SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT)));
assertThat(response.getComponentsList()).extracting(Component::getKey)
- .containsOnly(project.getDbKey());
+ .containsOnly(project.getKey());
}
@Test
@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);
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);
.executeProtobuf(SearchProjectsWsResponse.class);
assertThat(protobufResult.getComponentsList()).extracting(Component::getKey)
- .containsExactly(project1.getDbKey(), project2.getDbKey(), project3.getDbKey());
+ .containsExactly(project1.getKey(), project2.getKey(), project3.getKey());
}
@Test
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
assertThat(result.getComponentsList())
.extracting(Component::getKey)
- .containsExactlyInAnyOrder(project1.getDbKey(), project2.getDbKey());
+ .containsExactlyInAnyOrder(project1.getKey(), project2.getKey());
}
@Test
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
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
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
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
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
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
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
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
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
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
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");
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
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
.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));
}
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
assertThat(result.getComponentsList()).extracting(Component::getKey)
.containsExactly(
Stream.of(application1, application2, application3)
- .map(ComponentDto::getDbKey)
+ .map(ComponentDto::getKey)
.toArray(String[]::new));
}
assertThat(result.getComponentsList()).extracting(Component::getKey)
.containsExactly(
Stream.of(project1, project2, project3)
- .map(ComponentDto::getDbKey)
+ .map(ComponentDto::getKey)
.toArray(String[]::new));
}
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
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
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
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
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
SearchProjectsWsResponse result = call(request);
assertThat(result.getComponentsList()).extracting(Component::getKey)
- .containsExactlyInAnyOrder(project.getDbKey());
+ .containsExactlyInAnyOrder(project.getKey());
}
@Test
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
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
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();
}
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)));
}
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)));
}
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)
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");
}
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");
}
ComponentDto view = db.components().insertPrivatePortfolio();
userSession.addProjectPermission(USER, view);
- ShowWsResponse result = newRequest(view.getDbKey());
+ ShowWsResponse result = newRequest(view.getKey());
assertThat(result.getComponent().hasVisibility()).isTrue();
}
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();
}
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())
ComponentDto componentDto = newPrivateProjectDto("project-uuid");
db.components().insertProjectAndSnapshot(componentDto);
- String componentDtoDbKey = componentDto.getDbKey();
+ String componentDtoDbKey = componentDto.getKey();
assertThatThrownBy(() -> newRequest(componentDtoDbKey))
.isInstanceOf(ForbiddenException.class);
}
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)
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) {
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),
.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")
@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();
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"
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey, Suggestion::getIsRecentlyBrowsed)
- .containsExactly(tuple(project.getDbKey(), true));
+ .containsExactly(tuple(project.getKey(), true));
}
@Test
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"
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey, Suggestion::getIsRecentlyBrowsed)
- .containsExactly(tuple(project.getDbKey(), true));
+ .containsExactly(tuple(project.getKey(), true));
}
@Test
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
- .setParam(PARAM_RECENTLY_BROWSED, project.getDbKey())
+ .setParam(PARAM_RECENTLY_BROWSED, project.getKey())
.executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList())
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey, Suggestion::getIsFavorite)
- .containsExactly(tuple(project.getDbKey(), true));
+ .containsExactly(tuple(project.getKey(), true));
}
@Test
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"
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
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
@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())
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())
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
- .setParam(PARAM_QUERY, project.getDbKey())
+ .setParam(PARAM_QUERY, project.getKey())
.executeProtobuf(SuggestionsWsResponse.class);
// assert match in qualifier "TRK"
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey)
- .containsExactly(project.getDbKey());
+ .containsExactly(project.getKey());
}
@Test
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
- .setParam(PARAM_QUERY, project.getDbKey())
+ .setParam(PARAM_QUERY, project.getKey())
.executeProtobuf(SuggestionsWsResponse.class);
// assert match in qualifier "TRK"
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()
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey, Suggestion::getName)
- .containsExactlyInAnyOrder(tuple(project1.getDbKey(), project1.name()));
+ .containsExactlyInAnyOrder(tuple(project1.getKey(), project1.name()));
}
@Test
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()
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey)
- .containsOnly(project.getDbKey());
+ .containsOnly(project.getKey());
}
@Test
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())
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()
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()
logInWithBrowsePermission(project);
String response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getDbKey())
+ .setParam(PARAM_COMPONENT, project.getKey())
.execute()
.getInput();
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")
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")
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");
}
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);
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");
}
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"));
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");
@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()
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);
.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
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
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
db.commit();
TestRequest request = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getDbKey());
+ .setParam(PARAM_COMPONENT, project.getKey());
assertThatThrownBy(request::execute)
.isInstanceOf(ForbiddenException.class);
}
db.commit();
TestRequest request = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getDbKey())
+ .setParam(PARAM_COMPONENT, project.getKey())
.setParam(Param.PAGE_SIZE, "501");
assertThatThrownBy(request::execute)
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)
@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()
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);
}
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);
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"))
@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);
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);
@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()));
@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()));
" <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();
" <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();
" <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();
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" +
" <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
" <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();
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);
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),
" <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();
" <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();
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())));
}
}
@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" +
" <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())
" <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())
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);
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() {
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" +
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
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)
}
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() {
@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();
@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);
@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);
@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();
@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();
.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
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"));
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"));
@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)
@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)
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");
@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)
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()
@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);
@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"));
@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);
@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"));
@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);
@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
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)
@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));
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
- .setParam(PARAM_COMPONENT_KEYS, application.getDbKey())
+ .setParam(PARAM_COMPONENT_KEYS, application.getKey())
.executeProtobuf(SearchWsResponse.class);
assertThat(result.getIssuesList()).isEmpty();
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
- .setParam(PARAM_COMPONENT_KEYS, application.getDbKey())
+ .setParam(PARAM_COMPONENT_KEYS, application.getKey())
.executeProtobuf(SearchWsResponse.class);
assertThat(result.getIssuesList()).isEmpty();
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);
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)
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);
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);
indexIssues();
SearchWsResponse result = ws.newRequest()
- .setParam(PARAM_COMPONENT_KEYS, branch.getDbKey())
+ .setParam(PARAM_COMPONENT_KEYS, branch.getKey())
.executeProtobuf(SearchWsResponse.class);
assertThat(result.getIssuesList()).isEmpty();
.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()
.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()
.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();
.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()
.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();
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")
@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();
@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();
@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)
@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);
@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();
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"))
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"))
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"))
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"))
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"))
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")
@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"))
@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)
@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)
@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")));
@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);
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);
@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);
String projectUuid = "project_uuid_" + randomAlphanumeric(5);
ComponentDto projectDto = newPrivateProjectDto();
- projectDto.setProjectUuid(projectUuid);
+ projectDto.setBranchUuid(projectUuid);
UserDto userDto = newUserDto();
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
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
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
.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"));
@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())
.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();
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));
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();
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);
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();
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));
@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);
@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();
@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));
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();
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() {
@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);
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))
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);
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();
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);
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
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);
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);
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);
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
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();
}
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");
}
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();
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();
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");
}
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");
}
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");
}
project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
SearchHistoryRequest request = SearchHistoryRequest.builder()
- .setComponent(project.getDbKey())
+ .setComponent(project.getKey())
.setMetrics(singletonList(complexityMetric.getKey()))
.build();
userSession.addProjectPermission(UserRole.USER, project);
SearchHistoryRequest request = SearchHistoryRequest.builder()
- .setComponent(project.getDbKey())
+ .setComponent(project.getKey())
.setMetrics(singletonList(complexityMetric.getKey()))
.build();
db.commit();
SearchHistoryRequest request = SearchHistoryRequest.builder()
- .setComponent(project.getDbKey())
+ .setComponent(project.getKey())
.setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey()))
.build();
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);
db.commit();
SearchHistoryRequest request = SearchHistoryRequest.builder()
- .setComponent(project.getDbKey())
+ .setComponent(project.getKey())
.setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey()))
.setPage(2)
.setPageSize(3)
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))
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);
// 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);
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);
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();
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();
.addProjectPermission(UserRole.USER, application, project1);
SearchHistoryRequest request = SearchHistoryRequest.builder()
- .setComponent(application.getDbKey())
+ .setComponent(application.getKey())
.setMetrics(singletonList(complexityMetric.getKey()))
.build();
@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()
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();
db.commit();
SearchHistoryRequest request = SearchHistoryRequest.builder()
- .setComponent(project.getDbKey())
+ .setComponent(project.getKey())
.setMetrics(singletonList(stringMetric.getKey()))
.build();
SearchHistoryResponse result = call(request);
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())
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);
}
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);
}
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);
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);
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);
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));
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
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);
}
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);
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);
}
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");
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]");
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))
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) {
.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)
@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()
@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()
.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
.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)
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);
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
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();
@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()
.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
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);
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();
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
@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);
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()));
}
}
newRequest()
.setParam(PARAM_GROUP_NAME, aGroup.getName())
- .setParam(PARAM_PROJECT_KEY, project.getDbKey())
+ .setParam(PARAM_PROJECT_KEY, project.getKey())
.setParam(PARAM_PERMISSION, ADMIN)
.execute();
.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
.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)
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);
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
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();
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();
.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
.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)
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);
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
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
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;
public void apply_template_with_project_key() {
loginAsAdmin();
- newRequest(template1.getUuid(), null, project.getDbKey());
+ newRequest(template1.getUuid(), null, project.getKey());
assertTemplate1AppliedToProject();
}
@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();
@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();
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);
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);
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);
@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();
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, ","))
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);
ComponentDto toDelete2 = db.components().insertPrivateProject();
ws.newRequest()
- .setParam("projects", toDelete1.getDbKey() + "," + toDelete2.getDbKey())
+ .setParam("projects", toDelete1.getKey() + "," + toDelete2.getKey())
.execute();
verifyComponentDeleted(toDelete1, toDelete2);
when(projectDefaultVisibility.get(any())).thenReturn(Visibility.PUBLIC);
}
- @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);
.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);
}
@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()
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)));
}
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)));
}
new WsActionTester(underTest)
.newRequest()
- .setParam(PARAM_PROJECT, project.getDbKey())
+ .setParam(PARAM_PROJECT, project.getKey())
.execute();
UserDto userReloaded = dbClient.userDao().selectByUuid(dbSession, insert.getUuid());
.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);
}
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);
}
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() {
@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")
@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);
@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);
@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);
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());
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());
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());
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());
@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());
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());
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());
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());
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
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[] {}));
@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);
assertThat(result.getProjectsList())
.extracting(Project::getKey)
- .containsExactlyInAnyOrder(project.getDbKey());
+ .containsExactlyInAnyOrder(project.getKey());
}
@Test
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"));
}
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));
}
@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()
@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()
@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)
@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(
@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()
@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);
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());
}
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));
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 {
@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)
@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())
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);
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();
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);
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);
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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) {
@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)
@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));
@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"));
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)
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();
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();
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();
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();
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();
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();
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)
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());
@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"));
@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));
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());
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());
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());
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());
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);
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)
userSession.anonymous();
ComponentDto project = db.components().insertPrivateProject();
- var projectDbKey = project.getDbKey();
+ var projectDbKey = project.getKey();
assertThatThrownBy(() -> call(projectDbKey))
.isInstanceOf(ForbiddenException.class);
}
toProjectDto(project2, 1L))
.addProjectPermission(UserRole.USER, application, project1);
- var projectDbKey = application.getDbKey();
+ var projectDbKey = application.getKey();
assertThatThrownBy(() -> call(projectDbKey))
.isInstanceOf(ForbiddenException.class);
}
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");
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);
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);
@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
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);
}
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());
}
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");
}
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());
}
assertThatThrownBy(() -> {
actionTester.newRequest()
.setMethod("POST")
- .setParam("key", branch.getDbKey())
+ .setParam("key", branch.getKey())
.execute();
})
.isInstanceOf(NotFoundException.class);
}
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)
assertThatThrownBy(() -> {
underTest.newRequest()
- .setParam(KEY_PARAM, branch.getDbKey())
+ .setParam(KEY_PARAM, branch.getKey())
.execute();
})
.isInstanceOf(NotFoundException.class);
}
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) {
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();
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
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) {
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);
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
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");
private static ProjectMeasuresDoc newDoc(ComponentDto project) {
return new ProjectMeasuresDoc()
.setId(project.uuid())
- .setKey(project.getDbKey())
+ .setKey(project.getKey())
.setName(project.name());
}
@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"))
@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"))
@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"))
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));
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
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) {
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
assertThatThrownBy(() -> ws.newRequest()
.setParam("gateId", qualityGate.getUuid())
- .setParam("projectKey", project.getDbKey())
+ .setParam("projectKey", project.getKey())
.execute())
.isInstanceOf(ForbiddenException.class);
}
assertThatThrownBy(() -> ws.newRequest()
.setParam("gateId", qualityGate.getUuid())
- .setParam("projectKey", project.getDbKey())
+ .setParam("projectKey", project.getKey())
.execute())
.isInstanceOf(ForbiddenException.class);
}
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) {
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) {
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam("project", project.getDbKey())
+ .setParam("project", project.getKey())
.setParam("language", "xoo")
.setParam("qualityProfile", "unknown")
.execute();
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) {
.onQualifiers(PROJECT)
.build());
- ListDefinitionsWsResponse result = executeRequest(project.getDbKey());
+ ListDefinitionsWsResponse result = executeRequest(project.getKey());
assertThat(result.getDefinitionsList()).hasSize(1);
}
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");
}
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");
}
userSession.logIn("project-admin").addProjectPermission(CODEVIEWER, project);
propertyDefinitions.addComponent(PropertyDefinition.builder("foo").build());
- assertThatThrownBy(() -> executeRequest(project.getDbKey()))
+ assertThatThrownBy(() -> executeRequest(project.getKey()))
.isInstanceOf(ForbiddenException.class);
}
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
}
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) {
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());
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());
}
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());
}
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");
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");
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");
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());
}
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");
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");
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
definitions.addComponent(PropertyDefinition.builder("foo").build());
assertThatThrownBy(() -> {
- executeRequest(project.getDbKey(), "foo");
+ executeRequest(project.getKey(), "foo");
})
.isInstanceOf(ForbiddenException.class);
}
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
}
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) {
insertFileWithData(file, newData("public class HelloWorld {", "}"));
TestResponse request = tester.newRequest()
- .setParam("resource", file.getDbKey())
+ .setParam("resource", file.getKey())
.execute();
assertJson(request.getInput()).isSimilarTo("[\n" +
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();
ComponentDto file = db.components().insertComponent(newFileDto(project));
assertThatThrownBy(() -> tester.newRequest()
- .setParam("resource", file.getDbKey())
+ .setParam("resource", file.getKey())
.execute())
.isInstanceOf(ForbiddenException.class);
}
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) {
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();
@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);
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
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();
@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();
}
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) {
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
init();
- verifySuccess(project.getDbKey());
+ verifySuccess(project.getKey());
}
@Test
userSession.logIn().setSystemAdministrator();
init();
- verifySuccess(project.getDbKey());
+ verifySuccess(project.getKey());
}
@Test
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
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
.getInput();
assertJson(json).isSimilarTo("{" +
- " \"key\": \"" + subportfolio.getDbKey() + "\"," +
+ " \"key\": \"" + subportfolio.getKey() + "\"," +
" \"isFavorite\": true," +
" \"id\": \"" + subportfolio.uuid() + "\"," +
" \"name\": \"" + subportfolio.name() + "\"" +
.getInput();
assertJson(json).isSimilarTo("{" +
- " \"key\": \"" + portfolio.getDbKey() + "\"," +
+ " \"key\": \"" + portfolio.getKey() + "\"," +
" \"isFavorite\": true," +
" \"id\": \"" + portfolio.uuid() + "\"," +
" \"name\": \"" + portfolio.name() + "\"" +
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" +
"}");
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();
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();
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
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
userSession.addProjectPermission(UserRole.USER, project);
init();
- executeAndVerify(project.getDbKey(), "return_default_quality_gate.json");
+ executeAndVerify(project.getKey(), "return_default_quality_gate.json");
}
@Test
userSession.anonymous().addProjectPermission(UserRole.USER, project);
init(createPages());
- executeAndVerify(project.getDbKey(), "return_extensions.json");
+ executeAndVerify(project.getKey(), "return_extensions.json");
}
@Test
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");
.addProjectPermission(UserRole.ADMIN, project);
init(createPages());
- executeAndVerify(project.getDbKey(), "return_extensions_for_admin.json");
+ executeAndVerify(project.getKey(), "return_extensions_for_admin.json");
}
@Test
.build();
init(page1, page2);
- executeAndVerify(project.getDbKey(), "return_configuration_for_admin.json");
+ executeAndVerify(project.getKey(), "return_configuration_for_admin.json");
}
@Test
.thenReturn(projectResourceType);
init();
- executeAndVerify(project.getDbKey(), "return_configuration_with_all_properties.json");
+ executeAndVerify(project.getKey(), "return_configuration_with_all_properties.json");
}
@Test
.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
.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
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" +
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" +
init();
userSessionRule.addProjectPermission(UserRole.USER, project);
- String json = execute(project.getDbKey());
+ String json = execute(project.getKey());
assertThat(json).doesNotContain("\"configuration\"");
}
@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
userSession.addProjectPermission(UserRole.ADMIN, project);
init(createPages());
- execute(project.getDbKey());
+ execute(project.getKey());
}
@Test
userSession.logIn()
.addProjectPermission(UserRole.ADMIN, project)
.addPermission(GlobalPermission.ADMINISTER);
- assertJson(execute(project.getDbKey())).isSimilarTo("{\"visibility\": \"private\"}");
+ assertJson(execute(project.getKey())).isSimilarTo("{\"visibility\": \"private\"}");
}
@Test
userSession.logIn()
.addProjectPermission(UserRole.ADMIN, project)
.addPermission(GlobalPermission.ADMINISTER);
- assertJson(execute(project.getDbKey())).isSimilarTo("{\"visibility\": \"public\"}");
+ assertJson(execute(project.getKey())).isSimilarTo("{\"visibility\": \"public\"}");
}
@Test
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
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
init();
userSession.logIn();
- String projectDbKey = project.getDbKey();
+ String projectDbKey = project.getKey();
assertThatThrownBy(() -> execute(projectDbKey))
.isInstanceOf(ForbiddenException.class);
}
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);
.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());
}
@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()))
@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)
@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")
@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));
@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);
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
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();
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
String json = ws.newRequest()
- .setParam("componentKey", project.getDbKey())
+ .setParam("componentKey", project.getKey())
.execute()
.getInput();
.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
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");
userSession.logIn();
TestRequest request = ws.newRequest()
- .setParam("componentKey", project.getDbKey())
+ .setParam("componentKey", project.getKey())
.setParam("ceTaskId", "t1");
assertThatThrownBy(request::execute)
.isInstanceOf(IllegalArgumentException.class)
userSession.logIn();
TestRequest request = ws.newRequest()
- .setParam("componentKey", project.getDbKey())
+ .setParam("componentKey", project.getKey())
.setParam("webhook", "wh-uuid");
assertThatThrownBy(request::execute)
.isInstanceOf(IllegalArgumentException.class)
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
package org.sonar.scanner.scan;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
-import java.util.Set;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
if (!ComponentKeys.isValidProjectKey(projectDefinition.getKey())) {
validationMessages.add(format("\"%s\" is not a valid project key. %s.", projectDefinition.getKey(), ALLOWED_CHARACTERS_MESSAGE));
}
- Set<String> forbiddenNamePhrases = Set.of(":BRANCH:", ":PULLREQUEST:");
- if (forbiddenNamePhrases.stream().anyMatch(projectDefinition.getKey()::contains)) {
- validationMessages.add(format("\"%s\" is not a valid project key. Project key must not contain following phrases [%s]", projectDefinition.getKey(),
- String.join(", ", forbiddenNamePhrases)));
- }
}
private boolean isBranchFeatureAvailable() {
+ " '-', '_', '.' and ':', with at least one non-digit.");
}
- @Test
- public void fail_when_key_contains_invalid_phrases() {
- ProjectReactor reactorWithBranchInKey = createProjectReactor("test:BRANCH:test");
-
- assertThatThrownBy(() -> underTest.validate(reactorWithBranchInKey))
- .isInstanceOf(MessageException.class)
- .hasMessageContainingAll("\"test:BRANCH:test\" is not a valid project key. "
- + "Project key must not contain following phrases", ":BRANCH:", ":PULLREQUEST:");
-
- ProjectReactor reactorWithPRinKey = createProjectReactor("test:PULLREQUEST:test");
-
- assertThatThrownBy(() -> underTest.validate(reactorWithPRinKey))
- .isInstanceOf(MessageException.class)
- .hasMessageContainingAll("\"test:PULLREQUEST:test\" is not a valid project key. "
- + "Project key must not contain following phrases", ":BRANCH:", ":PULLREQUEST:");
- }
-
@Test
public void fail_when_only_digits() {
ProjectReactor reactor = createProjectReactor("12345");