aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-06-04 15:13:39 +0200
committerSonarTech <sonartech@sonarsource.com>2018-06-06 20:20:51 +0200
commitdce951b720155e47240cec570a557370545d8102 (patch)
treee5c1bf967c5111a0c6a8d000533045c6c4922c66
parent72b91edd716882445204b324aea703bb937d8cf5 (diff)
downloadsonarqube-dce951b720155e47240cec570a557370545d8102.tar.gz
sonarqube-dce951b720155e47240cec570a557370545d8102.zip
SONAR-10851 Make branch validation less strict on scanner side
No need to be more strict than server side.
-rw-r--r--server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Branch.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImpl.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/DefaultBranchImpl.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java14
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImplTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java10
16 files changed, 35 insertions, 41 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java b/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java
index 13b6c4ae023..c750ecabe2b 100644
--- a/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java
+++ b/server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java
@@ -46,7 +46,7 @@ public class ProjectConfigurationFactory {
Settings projectSettings = new ChildSettings(globalSettings);
addSettings(projectSettings, projectKey);
if (branch.getType() == BranchType.PULL_REQUEST) {
- addSettings(projectSettings, generatePullRequestKey(projectKey, branch.getPullRequestId()));
+ addSettings(projectSettings, generatePullRequestKey(projectKey, branch.getPullRequestKey()));
} else {
addSettings(projectSettings, generateBranchKey(projectKey, branch.getName()));
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java
index c6e00eb87e0..b1035913934 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java
@@ -105,7 +105,7 @@ public interface AnalysisMetadataHolder {
*
* @throws IllegalStateException if current analysis is not a pull request
*/
- String getPullRequestId();
+ String getPullRequestKey();
/**
* The project as represented by the main branch. It is used to load settings
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
index 157da3ac9cb..2fd4d7154d8 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
@@ -40,7 +40,7 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder
private final InitializedProperty<Analysis> baseProjectSnapshot = new InitializedProperty<>();
private final InitializedProperty<Boolean> crossProjectDuplicationEnabled = new InitializedProperty<>();
private final InitializedProperty<Branch> branch = new InitializedProperty<>();
- private final InitializedProperty<String> pullRequestId = new InitializedProperty<>();
+ private final InitializedProperty<String> pullRequestKey = new InitializedProperty<>();
private final InitializedProperty<Project> project = new InitializedProperty<>();
private final InitializedProperty<Integer> rootComponentRef = new InitializedProperty<>();
private final InitializedProperty<Map<String, QualityProfile>> qProfilesPerLanguage = new InitializedProperty<>();
@@ -151,16 +151,16 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder
}
@Override
- public MutableAnalysisMetadataHolder setPullRequestId(String pullRequestId) {
- checkState(!this.pullRequestId.isInitialized(), "Pull request id has already been set");
- this.pullRequestId.setProperty(pullRequestId);
+ public MutableAnalysisMetadataHolder setPullRequestKey(String pullRequestKey) {
+ checkState(!this.pullRequestKey.isInitialized(), "Pull request key has already been set");
+ this.pullRequestKey.setProperty(pullRequestKey);
return this;
}
@Override
- public String getPullRequestId() {
- checkState(pullRequestId.isInitialized(), "Pull request id has not been set");
- return pullRequestId.getProperty();
+ public String getPullRequestKey() {
+ checkState(pullRequestKey.isInitialized(), "Pull request key has not been set");
+ return pullRequestKey.getProperty();
}
@Override
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Branch.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Branch.java
index bc7fff0f769..c5defbb698a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Branch.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Branch.java
@@ -57,5 +57,5 @@ public interface Branch extends ComponentKeyGenerator {
/**
* @throws IllegalStateException if this branch configuration is not a pull request.
*/
- String getPullRequestId();
+ String getPullRequestKey();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java
index a23d83f5841..6727de64387 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java
@@ -62,9 +62,9 @@ public interface MutableAnalysisMetadataHolder extends AnalysisMetadataHolder {
MutableAnalysisMetadataHolder setBranch(Branch branch);
/**
- * @throws IllegalStateException if pull request id has already been set
+ * @throws IllegalStateException if pull request key has already been set
*/
- MutableAnalysisMetadataHolder setPullRequestId(String pullRequestId);
+ MutableAnalysisMetadataHolder setPullRequestKey(String pullRequestKey);
/**
* @throws IllegalStateException if project has already been set
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
index e7f179b283c..55540ec2617 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
@@ -181,7 +181,7 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor
private BranchImpl createBranch() {
org.sonar.server.computation.task.projectanalysis.analysis.Branch analysisBranch = analysisMetadataHolder.getBranch();
if (!analysisBranch.isLegacyFeature()) {
- String branchKey = analysisBranch.getType() == PULL_REQUEST ? analysisBranch.getPullRequestId() : analysisBranch.getName();
+ String branchKey = analysisBranch.getType() == PULL_REQUEST ? analysisBranch.getPullRequestKey() : analysisBranch.getName();
return new BranchImpl(analysisBranch.isMain(), branchKey, Branch.Type.valueOf(analysisBranch.getType().name()));
}
return null;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImpl.java
index a58a8ca987a..25583a007e6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImpl.java
@@ -88,7 +88,7 @@ public class BranchPersisterImpl implements BranchPersister {
dto.setMergeBranchUuid(branch.getMergeBranchUuid().orElse(null));
if (branch.getType() == BranchType.PULL_REQUEST) {
- dto.setKey(analysisMetadataHolder.getPullRequestId());
+ dto.setKey(analysisMetadataHolder.getPullRequestKey());
DbProjectBranches.PullRequestData pullRequestData = DbProjectBranches.PullRequestData.newBuilder()
.setBranch(branch.getName())
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/DefaultBranchImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/DefaultBranchImpl.java
index 63b49e588ef..341174f1a6b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/DefaultBranchImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/DefaultBranchImpl.java
@@ -86,7 +86,7 @@ public class DefaultBranchImpl implements Branch {
}
@Override
- public String getPullRequestId() {
+ public String getPullRequestKey() {
throw new IllegalStateException("Only a branch of type PULL_REQUEST can have a pull request id.");
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java
index 8592bb9d796..04c90437dff 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java
@@ -224,7 +224,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
@CheckForNull
private String getPullRequest() {
Branch branch = analysisMetadataHolder.getBranch();
- return branch.getType() == PULL_REQUEST ? analysisMetadataHolder.getPullRequestId() : null;
+ return branch.getType() == PULL_REQUEST ? analysisMetadataHolder.getPullRequestKey() : null;
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java
index 58d9a362a6d..a5971cad4f4 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java
@@ -247,27 +247,27 @@ public class AnalysisMetadataHolderImplTest {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
String pullRequestId = "pr-123";
- underTest.setPullRequestId(pullRequestId);
+ underTest.setPullRequestKey(pullRequestId);
- assertThat(underTest.getPullRequestId()).isEqualTo(pullRequestId);
+ assertThat(underTest.getPullRequestKey()).isEqualTo(pullRequestId);
}
@Test
public void getPullRequestId_throws_ISE_when_holder_is_not_initialized() {
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Pull request id has not been set");
+ expectedException.expectMessage("Pull request key has not been set");
- new AnalysisMetadataHolderImpl().getPullRequestId();
+ new AnalysisMetadataHolderImpl().getPullRequestKey();
}
@Test
public void setPullRequestId_throws_ISE_when_called_twice() {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
- underTest.setPullRequestId("pr-123");
+ underTest.setPullRequestKey("pr-123");
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Pull request id has already been set");
- underTest.setPullRequestId("pr-234");
+ expectedException.expectMessage("Pull request key has already been set");
+ underTest.setPullRequestKey("pr-234");
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java
index a24e7311c65..b9f445316cd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java
@@ -171,13 +171,13 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Muta
}
@Override
- public MutableAnalysisMetadataHolder setPullRequestId(String pullRequestId) {
- this.pullRequestId.setProperty(pullRequestId);
+ public MutableAnalysisMetadataHolder setPullRequestKey(String pullRequestKey) {
+ this.pullRequestId.setProperty(pullRequestKey);
return this;
}
@Override
- public String getPullRequestId() {
+ public String getPullRequestKey() {
checkState(pullRequestId.isInitialized(), "Pull request id has not been set");
return pullRequestId.getProperty();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java
index 5eb99bc59f3..a3181b811e9 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java
@@ -122,13 +122,13 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen
}
@Override
- public String getPullRequestId() {
- return delegate.getPullRequestId();
+ public String getPullRequestKey() {
+ return delegate.getPullRequestKey();
}
@Override
- public MutableAnalysisMetadataHolder setPullRequestId(String pullRequestId) {
- delegate.setPullRequestId(pullRequestId);
+ public MutableAnalysisMetadataHolder setPullRequestKey(String pullRequestKey) {
+ delegate.setPullRequestKey(pullRequestKey);
return this;
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
index 4270765b208..ce56b6e5869 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
@@ -302,7 +302,7 @@ public class PostProjectAnalysisTasksExecutorTest {
}
@Override
- public String getPullRequestId() {
+ public String getPullRequestKey() {
throw new UnsupportedOperationException();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImplTest.java
index 12a8855e42b..80a1a8e8b57 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterImplTest.java
@@ -87,7 +87,7 @@ public class BranchPersisterImplTest {
public void persist_pull_request_data() {
String pullRequestId = "pr-123";
analysisMetadataHolder.setBranch(createBranch(BranchType.PULL_REQUEST, false, pullRequestId));
- analysisMetadataHolder.setPullRequestId(pullRequestId);
+ analysisMetadataHolder.setPullRequestKey(pullRequestId);
treeRootHolder.setRoot(BRANCH);
// add main branch in project table and in metadata
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java
index 13c3ade55c2..8ef1a6b0178 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java
@@ -944,7 +944,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
}
@Override
- public String getPullRequestId() {
+ public String getPullRequestKey() {
throw new UnsupportedOperationException();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java
index b7bcc98ba6b..6678e551536 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java
@@ -20,23 +20,18 @@
package org.sonar.server.computation.task.projectanalysis.step;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
-import java.util.stream.Stream;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
-import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent;
import org.sonar.api.notifications.Notification;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.Duration;
@@ -68,7 +63,6 @@ import static java.util.Arrays.stream;
import static java.util.Collections.shuffle;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Stream.concat;
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.ArgumentMatchers.eq;
@@ -233,7 +227,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close();
when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true);
analysisMetadataHolder.setBranch(newPullRequest());
- analysisMetadataHolder.setPullRequestId(PULL_REQUEST_ID);
+ analysisMetadataHolder.setPullRequestKey(PULL_REQUEST_ID);
underTest.execute();
@@ -500,7 +494,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
when(branch.isMain()).thenReturn(false);
when(branch.getType()).thenReturn(PULL_REQUEST);
when(branch.getName()).thenReturn(BRANCH_NAME);
- when(branch.getPullRequestId()).thenReturn(PULL_REQUEST_ID);
+ when(branch.getPullRequestKey()).thenReturn(PULL_REQUEST_ID);
return branch;
}