aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task-projectanalysis/src/main/java
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2019-06-07 12:25:22 +0200
committerSonarTech <sonartech@sonarsource.com>2019-08-12 20:21:13 +0200
commit05c8a2e004e9cc17a4d5963a42c835753eefb367 (patch)
tree2f70ae5589ff39d9f8532c1e628947784a1f9306 /server/sonar-ce-task-projectanalysis/src/main/java
parent21805ac1812e1db25ea1b8267593c6893b367fb4 (diff)
downloadsonarqube-05c8a2e004e9cc17a4d5963a42c835753eefb367.tar.gz
sonarqube-05c8a2e004e9cc17a4d5963a42c835753eefb367.zip
SONAR-12197 completely drop "sonar.branch" code
Diffstat (limited to 'server/sonar-ce-task-projectanalysis/src/main/java')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Branch.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchLoader.java18
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java30
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactory.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java17
8 files changed, 16 insertions, 68 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
index 46e2b3bf3b2..4f9699e9fa5 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
@@ -153,7 +153,7 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder
checkState(!this.branch.isInitialized(), "Branch has already been set");
boolean isCommunityEdition = editionProvider.get().filter(t -> t == EditionProvider.Edition.COMMUNITY).isPresent();
checkState(
- !isCommunityEdition || branch.isMain() || branch.isLegacyFeature(),
+ !isCommunityEdition || branch.isMain(),
"Branches and Pull Requests are not supported in Community Edition");
this.branch.setProperty(branch);
return this;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Branch.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Branch.java
index c4a022f0724..66b2e175f31 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Branch.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Branch.java
@@ -31,12 +31,6 @@ public interface Branch extends ComponentKeyGenerator {
boolean isMain();
/**
- * Whether branch has been created through the legacy configuration
- * (scanner parameter sonar.branch) or not
- */
- boolean isLegacyFeature();
-
- /**
* Name of the branch
*/
String getName();
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
index 0b5e7f0c617..1f14c24c131 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
@@ -230,11 +230,8 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor
@CheckForNull
private BranchImpl createBranch() {
org.sonar.ce.task.projectanalysis.analysis.Branch analysisBranch = analysisMetadataHolder.getBranch();
- if (!analysisBranch.isLegacyFeature()) {
- String branchKey = analysisBranch.getType() == PULL_REQUEST ? analysisBranch.getPullRequestKey() : analysisBranch.getName();
- return new BranchImpl(analysisBranch.isMain(), branchKey, Branch.Type.valueOf(analysisBranch.getType().name()));
- }
- return null;
+ String branchKey = analysisBranch.getType() == PULL_REQUEST ? analysisBranch.getPullRequestKey() : analysisBranch.getName();
+ return new BranchImpl(analysisBranch.isMain(), branchKey, Branch.Type.valueOf(analysisBranch.getType().name()));
}
private static QualityGate.Status convert(QualityGateStatus status) {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchLoader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchLoader.java
index eef07f70d3e..0a85a218401 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchLoader.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchLoader.java
@@ -24,7 +24,6 @@ import org.sonar.api.utils.MessageException;
import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolder;
import org.sonar.scanner.protocol.output.ScannerReport;
-import static org.apache.commons.lang.StringUtils.trimToNull;
import static org.sonar.scanner.protocol.output.ScannerReport.Metadata.BranchType.UNSET;
public class BranchLoader {
@@ -41,21 +40,12 @@ public class BranchLoader {
}
public void load(ScannerReport.Metadata metadata) {
- String deprecatedBranch = trimToNull(metadata.getDeprecatedBranch());
- String branchName = trimToNull(metadata.getBranchName());
-
- if (deprecatedBranch != null && branchName != null) {
- throw MessageException.of("Properties sonar.branch and sonar.branch.name can't be set together");
- }
-
- if (delegate == null && hasBranchProperties(metadata)) {
- throw MessageException.of("Current edition does not support branch feature");
- }
-
- if (delegate != null && deprecatedBranch == null) {
+ if (delegate != null) {
delegate.load(metadata);
+ } else if (hasBranchProperties(metadata)) {
+ throw MessageException.of("Current edition does not support branch feature");
} else {
- metadataHolder.setBranch(new DefaultBranchImpl(deprecatedBranch));
+ metadataHolder.setBranch(new DefaultBranchImpl());
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java
index 1a15ad8e243..a42889a088b 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java
@@ -20,36 +20,23 @@
package org.sonar.ce.task.projectanalysis.component;
import javax.annotation.Nullable;
-import org.sonar.api.utils.MessageException;
import org.sonar.ce.task.projectanalysis.analysis.Branch;
import org.sonar.core.component.ComponentKeys;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
-import static java.lang.String.format;
import static org.apache.commons.lang.StringUtils.isEmpty;
import static org.apache.commons.lang.StringUtils.trimToNull;
/**
- * The default (and legacy) implementation of {@link Branch}. It is used
- * when scanner is configured with parameter "sonar.branch" or when no branch is provided and the branch plugin is not installed.
- * A legacy branch is implemented as a fork of the project, so any branch is considered as "main".
+ * Implementation of {@link Branch} for default/main branch. It is used
+ * when no branch is provided as a scanner parameter or if the branch plugin is not installed.
*/
public class DefaultBranchImpl implements Branch {
private final String branchName;
- private final boolean isLegacyBranch;
public DefaultBranchImpl() {
- this(null);
- }
-
- public DefaultBranchImpl(@Nullable String name) {
- this.isLegacyBranch = (name != null);
- this.branchName = (name == null) ? BranchDto.DEFAULT_MAIN_BRANCH_NAME : name;
- if (!ComponentKeys.isValidLegacyBranch(branchName)) {
- throw MessageException.of(format("\"%s\" is not a valid branch name. "
- + "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branchName));
- }
+ this.branchName = BranchDto.DEFAULT_MAIN_BRANCH_NAME;
}
@Override
@@ -68,19 +55,13 @@ public class DefaultBranchImpl implements Branch {
}
@Override
- public boolean isLegacyFeature() {
- return isLegacyBranch;
- }
-
- @Override
public String getName() {
return branchName;
}
@Override
public boolean supportsCrossProjectCpd() {
- // only on regular project, not on branches
- return !isLegacyBranch;
+ return true;
}
@Override
@@ -95,9 +76,6 @@ public class DefaultBranchImpl implements Branch {
@Override
public String generateKey(String projectKey, @Nullable String fileOrDirPath) {
- if (isLegacyBranch) {
- projectKey = ComponentKeys.createKey(projectKey, branchName);
- }
if (isEmpty(fileOrDirPath)) {
return projectKey;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactory.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactory.java
index 1bf255cd626..182e6cc5b51 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactory.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactory.java
@@ -121,7 +121,7 @@ public class NotificationFactory {
Project.Builder builder = new Project.Builder(project.getUuid())
.setKey(project.getKey())
.setProjectName(project.getName());
- if (!branch.isLegacyFeature() && branch.getType() != PULL_REQUEST && !branch.isMain()) {
+ if (branch.getType() != PULL_REQUEST && !branch.isMain()) {
builder.setBranchName(branch.getName());
}
return builder.build();
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
index 96abdd05c0e..d4dc2ffcd64 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
@@ -135,7 +135,7 @@ public class BuildComponentTreeStep implements ComputationStep {
Branch branch = analysisMetadataHolder.getBranch();
// for non-legacy branches, the public key is different from the DB key.
- if (!branch.isLegacyFeature() && !branch.isMain()) {
+ if (!branch.isMain()) {
return new DefaultBranchImpl();
}
return branch;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
index a0765550a60..df5c1c05f46 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
@@ -25,7 +25,6 @@ import java.util.List;
import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.MessageException;
import org.sonar.ce.task.CeTask;
import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolder;
@@ -34,7 +33,6 @@ import org.sonar.ce.task.projectanalysis.analysis.ScannerPlugin;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
import org.sonar.ce.task.projectanalysis.component.BranchLoader;
import org.sonar.ce.task.step.ComputationStep;
-import org.sonar.core.component.ComponentKeys;
import org.sonar.core.platform.PluginRepository;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
@@ -104,7 +102,6 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
* @return a {@link Runnable} to execute some checks on the project at the end of the step
*/
private Runnable loadProject(ScannerReport.Metadata reportMetadata, Organization organization) {
- String reportProjectKey = projectKeyFromReport(reportMetadata);
CeTask.Component mainComponent = mandatoryComponent(ceTask.getMainComponent());
String mainComponentKey = mainComponent.getKey()
.orElseThrow(() -> MessageException.of(format(
@@ -115,14 +112,14 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
.orElseThrow(() -> MessageException.of(format(
"Compute Engine task component key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
component.getUuid())));
- ComponentDto dto = toProject(reportProjectKey);
+ ComponentDto dto = toProject(reportMetadata.getProjectKey());
analysisMetadata.setProject(Project.from(dto));
return () -> {
- if (!mainComponentKey.equals(reportProjectKey)) {
+ if (!mainComponentKey.equals(reportMetadata.getProjectKey())) {
throw MessageException.of(format(
"ProjectKey in report (%s) is not consistent with projectKey under which the report has been submitted (%s)",
- reportProjectKey,
+ reportMetadata.getProjectKey(),
mainComponentKey));
}
if (!dto.getOrganizationUuid().equals(organization.getUuid())) {
@@ -233,14 +230,6 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
}
}
- private static String projectKeyFromReport(ScannerReport.Metadata reportMetadata) {
- String deprecatedBranch = reportMetadata.getDeprecatedBranch();
- if (StringUtils.isNotEmpty(deprecatedBranch)) {
- return ComponentKeys.createKey(reportMetadata.getProjectKey(), deprecatedBranch);
- }
- return reportMetadata.getProjectKey();
- }
-
@Override
public String getDescription() {
return "Load analysis metadata";