import static org.sonar.db.component.ComponentDto.removeBranchAndPullRequestFromKey;
/**
- * Cache a map between component keys and uuids in the merge branch and optionally the target branch (for PR and SLB, and only if this target branch is analyzed)
+ * Cache a map between component keys and uuids in the merge branch and optionally the target branch (for PRs, and only if this target branch is analyzed)
*/
public class MergeAndTargetBranchComponentUuids {
private final AnalysisMetadataHolder analysisMetadataHolder;
import static org.sonar.db.component.ComponentDto.removeBranchAndPullRequestFromKey;
/**
- * Cache a map of component key -> set<uuid> in sibling branches/PR that have open issues
+ * Cache a map of component key -> set<uuid> in sibling PRs that have open issues
*/
public class SiblingComponentsWithOpenIssues {
private final DbClient dbClient;
uuidsByKey = new HashMap<>();
try (DbSession dbSession = dbClient.openSession(false)) {
+ // for the time being it still tries to load from short living branches
List<KeyWithUuidDto> components = dbClient.componentDao().selectAllSiblingComponentKeysHavingOpenIssues(dbSession, referenceBranchUuid, currentBranchUuid);
for (KeyWithUuidDto dto : components) {
uuidsByKey.computeIfAbsent(removeBranchAndPullRequestFromKey(dto.key()), s -> new HashSet<>()).add(dto.uuid());
+ 27 // level 1
+ 65 // content of DaoModule
+ 3 // content of EsModule
- + 51 // content of CorePropertyDefinitions
+ + 50 // content of CorePropertyDefinitions
+ 1 // StopFlagContainer
);
assertThat(
@Test
public void verify_toString() {
assertThat(underTest.toString()).isEqualTo(
- "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=SHORT}, qualityGate=EvaluatedQualityGate{qualityGate=QualityGate{id=id, name='name', conditions=[]}, status=ERROR, evaluatedConditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500, revision=sha1}}");
+ "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=LONG}, qualityGate=EvaluatedQualityGate{qualityGate=QualityGate{id=id, name='name', conditions=[]}, status=ERROR, evaluatedConditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500, revision=sha1}}");
}
}
public static final String ORGANIZATION = "sonar.organization";
public static final String BRANCH_NAME = "sonar.branch.name";
+ @Deprecated
public static final String BRANCH_TARGET = "sonar.branch.target";
public static final String PULL_REQUEST_KEY = "sonar.pullrequest.key";
.description("Provide a name for the branch being analyzed. It might match an existing branch of the project, otherwise a new branch will be created.")
.hidden()
.build(),
- PropertyDefinition.builder(BRANCH_TARGET)
- .name("Optional name of target branch to merge into")
- .description(
- "Defines the target branch of the branch being analyzed. The main branch cannot have a target. "
- + "If no target is defined, the main branch is used as the target.")
- .hidden()
- .build(),
PropertyDefinition.builder(PULL_REQUEST_BRANCH)
.name("Optional name of pull request")
.description("Provide a name for the pull request being analyzed. It might match an existing pull request of the project, otherwise a new pull request will be created.")
@Test
public void all() {
List<PropertyDefinition> defs = CorePropertyDefinitions.all();
- assertThat(defs).hasSize(51);
+ assertThat(defs).hasSize(50);
}
@Test
builder.setBranchName(branchConfiguration.branchName());
BranchType branchType = toProtobufBranchType(branchConfiguration.branchType());
builder.setBranchType(branchType);
- String referenceBranch = branchConfiguration.longLivingSonarReferenceBranch();
+ String referenceBranch = branchConfiguration.referenceBranchName();
if (referenceBranch != null) {
builder.setMergeBranchName(referenceBranch);
}
public ProjectRepositories get() {
if (project == null) {
Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
- project = loader.load(scannerProperties.getProjectKey(), branchConfig.longLivingSonarReferenceBranch());
+ project = loader.load(scannerProperties.getProjectKey(), branchConfig.referenceBranchName());
profiler.stopInfo();
}
import static org.apache.commons.lang.StringUtils.isNotEmpty;
import static org.sonar.core.config.ScannerProperties.BRANCHES_DOC_LINK;
import static org.sonar.core.config.ScannerProperties.BRANCH_NAME;
-import static org.sonar.core.config.ScannerProperties.BRANCH_TARGET;
import static org.sonar.core.config.ScannerProperties.PULL_REQUEST_BASE;
import static org.sonar.core.config.ScannerProperties.PULL_REQUEST_BRANCH;
import static org.sonar.core.config.ScannerProperties.PULL_REQUEST_KEY;
}
private void validateBranchParamsWhenPluginAbsent(List<String> validationMessages) {
- for (String param : Arrays.asList(BRANCH_NAME, BRANCH_TARGET)) {
+ for (String param : Arrays.asList(BRANCH_NAME)) {
if (isNotEmpty(settings.get(param).orElse(null))) {
validationMessages.add(format("To use the property \"%s\" and analyze branches, Developer Edition or above is required. "
+ "See %s for more information.", param, BRANCHES_DOC_LINK));
public interface BranchConfiguration {
/**
- * The type of the branch we're on, determined by:
- * - If the specified branch exists on the server, then its type
- * - If the branch name matches the pattern of long-lived branches, then it's long-lived
- * - Otherwise it's short-lived
- *
* @return type of the current branch
*/
BranchType branchType();
}
/**
- * For long/short living branches, this is the value of sonar.branch.name, and fallback on the default branch name configured in SQ
+ * For branches, this is the value of sonar.branch.name, and fallback on the default branch name configured in SQ
* For PR: the name of the branch containing PR changes (sonar.pullrequest.branch)
*
* @return null if the branch feature is not available or no branch was specified.
String branchName();
/**
- * The long living server branch from which we should load project settings/quality profiles/compare changed files/...
- * For long living branches, this is the sonar.branch.target (default to default branch) in case of first analysis,
- * otherwise it's the branch itself.
- * For short living branches, we look at sonar.branch.target (default to default branch). If it exists but is a short living branch or PR, we will
- * transitively use its own target.
+ * The branch from which we should load project settings/quality profiles/compare changed files/...
+ * For branches, it's the to default branch in case of first analysis, otherwise it's the branch itself.
* For PR, we look at sonar.pullrequest.base (default to default branch). If it exists but is a short living branch or PR, we will
* transitively use its own target. If base is not analyzed, we will use default branch.
*
* @return null if the branch feature is not available or no branch was specified.
*/
@CheckForNull
- String longLivingSonarReferenceBranch();
+ String referenceBranchName();
/**
- * Raw value of sonar.branch.target or sonar.pullrequest.base (fallback to the default branch).
+ * For P/Rs, it's the raw value of 'sonar.pullrequest.base'.
+ * For branches it's always null.
* In the scanner side, it will be used by the SCM to compute changed files and changed lines.
*
- * @return null if the branch feature is not available, the branch being analyzed is the main branch or no branch was specified.
+ * @return null if the branch feature is not available or if it's not a P/R.
*/
@CheckForNull
String targetBranchName();
@CheckForNull
@Override
- public String longLivingSonarReferenceBranch() {
+ public String referenceBranchName() {
return null;
}
@CheckForNull
@Override
- public String longLivingSonarReferenceBranch() {
+ public String referenceBranchName() {
return longLivingSonarReferenceBranch;
}
underTest.validate(reactor);
}
- @Test
- public void fail_when_branch_target_is_specified_but_branch_plugin_not_present() {
- ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
- ProjectReactor reactor = new ProjectReactor(def);
-
- when(settings.get(eq(ScannerProperties.BRANCH_TARGET))).thenReturn(Optional.of("feature1"));
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("To use the property \"sonar.branch.target\" and analyze branches, Developer Edition or above is required");
-
- underTest.validate(reactor);
- }
-
@Test
public void fail_when_pull_request_id_specified_but_branch_plugin_not_present() {
ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");