]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11077 remove ambiguity in CE when supporting old branches
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 26 Jul 2018 20:32:43 +0000 (22:32 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 2 Aug 2018 18:21:34 +0000 (20:21 +0200)
server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java
server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java
server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java
server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java

index 73ecb04f18ba4db676f011f913e9c9c11fec655c..604db1297e79df4e0850848d607260194a71ccee 100644 (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();
index b266254de7838878eec97c197b5491fd0714f9e4..d4754b76a9b02d6e714f5bad4971b8c880588af9 100644 (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())
index 14153e3bc6ff833f28a7a6f8cad9c85ecaaa374f..7956a24ca5e514de636da54d7a8b4cc1ef2e6659 100644 (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);
 
index 5762994fcadb027e2820142fb0bcd2217146d576..222014360972b8ba9aec5b03ceb96b21f8ece6f8 100644 (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;
     }
 
index 6df58965ba63dd675d9ee30a58fdb0e7c5c545f2..d9486ceeba572b3c6b8a1cfe23d0e040ffc7f0cf 100644 (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(),
index 495b203611a0f1b8e8b43971e10ca08dabede8fa..59fbf71ad6fcbbe511a6892e1195c364814d0771 100644 (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);