From 22249fd4cc5891f7b370386ad59b1d402b286935 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 26 Jul 2018 22:32:43 +0200 Subject: [PATCH] SONAR-11077 remove ambiguity in CE when supporting old branches --- .../java/org/sonar/server/ce/queue/ReportSubmitter.java | 8 ++++---- .../main/java/org/sonar/server/ce/ws/SubmitAction.java | 5 +++-- .../java/org/sonar/server/component/ComponentUpdater.java | 4 ++-- .../java/org/sonar/server/component/NewComponent.java | 6 +++--- .../java/org/sonar/server/project/ws/CreateAction.java | 2 +- .../org/sonar/server/component/ComponentUpdaterTest.java | 4 ++-- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java b/server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java index 73ecb04f18b..604db1297e7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java @@ -74,15 +74,15 @@ public class ReportSubmitter { * @throws NotFoundException if the organization with the specified key does not exist * @throws IllegalArgumentException if the organization with the specified key is not the organization of the specified project (when it already exists in DB) */ - public CeTask submit(String organizationKey, String projectKey, @Nullable String projectBranch, @Nullable String projectName, Map characteristics, + public CeTask submit(String organizationKey, String projectKey, @Nullable String deprecatedBranch, @Nullable String projectName, Map characteristics, InputStream reportInput) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organizationDto = getOrganizationDtoOrFail(dbSession, organizationKey); - String effectiveProjectKey = ComponentKeys.createKey(projectKey, projectBranch); + String effectiveProjectKey = ComponentKeys.createKey(projectKey, deprecatedBranch); Optional component = dbClient.componentDao().selectByKey(dbSession, effectiveProjectKey); validateProject(dbSession, component, projectKey); ensureOrganizationIsConsistent(component, organizationDto); - ComponentDto project = component.or(() -> createProject(dbSession, organizationDto, projectKey, projectBranch, projectName)); + ComponentDto project = component.or(() -> createProject(dbSession, organizationDto, projectKey, deprecatedBranch, projectName)); checkScanPermission(project); return submitReport(dbSession, reportInput, project, characteristics); } @@ -152,7 +152,7 @@ public class ReportSubmitter { .setOrganizationUuid(organization.getUuid()) .setKey(projectKey) .setName(defaultIfBlank(projectName, projectKey)) - .setBranch(deprecatedBranch) + .setDeprecatedBranch(deprecatedBranch) .setQualifier(Qualifiers.PROJECT) .setPrivate(newProjectPrivate) .build(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java index b266254de78..d4754b76a9b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java @@ -80,6 +80,7 @@ public class SubmitAction implements CeWsAction { .setDescription("Key of project") .setExampleValue("my_project"); + // deprecated branch (see scanner parameter sonar.branch) action .createParam(PARAM_PROJECT_BRANCH) .setDescription("Optional branch of project") @@ -110,13 +111,13 @@ public class SubmitAction implements CeWsAction { .emptyAsNull() .or(defaultOrganizationProvider.get()::getKey); String projectKey = wsRequest.mandatoryParam(PARAM_PROJECT_KEY); - String projectBranch = wsRequest.param(PARAM_PROJECT_BRANCH); + String deprecatedBranch = wsRequest.param(PARAM_PROJECT_BRANCH); String projectName = abbreviate(defaultIfBlank(wsRequest.param(PARAM_PROJECT_NAME), projectKey), MAX_COMPONENT_NAME_LENGTH); Map characteristics = parseTaskCharacteristics(wsRequest); try (InputStream report = new BufferedInputStream(wsRequest.mandatoryParamAsPart(PARAM_REPORT_DATA).getInputStream())) { - CeTask task = reportSubmitter.submit(organizationKey, projectKey, projectBranch, projectName, characteristics, report); + CeTask task = reportSubmitter.submit(organizationKey, projectKey, deprecatedBranch, projectName, characteristics, report); Ce.SubmitResponse submitResponse = Ce.SubmitResponse.newBuilder() .setTaskId(task.getUuid()) .setProjectId(task.getComponentUuid()) diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java index 14153e3bc6f..7956a24ca5e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java @@ -87,8 +87,8 @@ public class ComponentUpdater { } private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) { - checkBranchFormat(newComponent.qualifier(), newComponent.branch()); - String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.branch()); + checkBranchFormat(newComponent.qualifier(), newComponent.deprecatedBranch()); + String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.deprecatedBranch()); checkRequest(!dbClient.componentDao().selectByKey(session, keyWithBranch).isPresent(), "Could not create %s, key already exists: %s", getQualifierToDisplay(newComponent.qualifier()), keyWithBranch); diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java b/server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java index 5762994fcad..22201436097 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java @@ -64,7 +64,7 @@ public class NewComponent { } @CheckForNull - public String branch() { + public String deprecatedBranch() { return branch; } @@ -98,8 +98,8 @@ public class NewComponent { return this; } - public Builder setBranch(@Nullable String branch) { - this.branch = branch; + public Builder setDeprecatedBranch(@Nullable String s) { + this.branch = s; return this; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java index 6df58965ba6..d9486ceeba5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java @@ -124,7 +124,7 @@ public class CreateAction implements ProjectsWsAction { .setOrganizationUuid(organization.getUuid()) .setKey(request.getKey()) .setName(request.getName()) - .setBranch(request.getBranch()) + .setDeprecatedBranch(request.getBranch()) .setPrivate(changeToPrivate) .setQualifier(PROJECT) .build(), diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java index 495b203611a..59fbf71ad6f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java @@ -141,7 +141,7 @@ public class ComponentUpdaterTest { NewComponent.newComponentBuilder() .setKey(DEFAULT_PROJECT_KEY) .setName(DEFAULT_PROJECT_NAME) - .setBranch("origin/master") + .setDeprecatedBranch("origin/master") .setOrganizationUuid(db.getDefaultOrganization().getUuid()) .build(), null); @@ -320,7 +320,7 @@ public class ComponentUpdaterTest { NewComponent.newComponentBuilder() .setKey(DEFAULT_PROJECT_KEY) .setName(DEFAULT_PROJECT_NAME) - .setBranch("origin?branch") + .setDeprecatedBranch("origin?branch") .setOrganizationUuid(db.getDefaultOrganization().getUuid()) .build(), null); -- 2.39.5