Browse Source

SONAR-11077 remove ambiguity in CE when supporting old branches

tags/7.5
Simon Brandhof 5 years ago
parent
commit
22249fd4cc

+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java View File

@@ -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<String, String> characteristics,
public CeTask submit(String organizationKey, String projectKey, @Nullable String deprecatedBranch, @Nullable String projectName, Map<String, String> 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<ComponentDto> 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();

+ 3
- 2
server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java View File

@@ -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<String, String> 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())

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java View File

@@ -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);


+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java View File

@@ -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;
}


+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java View File

@@ -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(),

+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java View File

@@ -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);

Loading…
Cancel
Save