aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2023-01-09 10:21:58 +0100
committersonartech <sonartech@sonarsource.com>2023-01-09 20:03:08 +0000
commit146e8dc7937fdc768961039db90f53613521abb1 (patch)
treee189c6a6a624a68107959c63f3fc9ebf9479a12e
parentd65568551dd4d46a7aa62ab3021f419ad4e3e78e (diff)
downloadsonarqube-146e8dc7937fdc768961039db90f53613521abb1.tar.gz
sonarqube-146e8dc7937fdc768961039db90f53613521abb1.zip
SONAR-17775 fixed a bug where old portfolio and app XMLs could not be sometimes imported
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java5
-rw-r--r--server/sonar-db-migration/src/main/resources/static/views.xsd4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java2
4 files changed, 12 insertions, 4 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java
index 21a95c2680f..dc2fa866a2e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java
@@ -31,6 +31,11 @@ import static com.google.common.base.Preconditions.checkArgument;
public class BranchDto {
public static final String DEFAULT_MAIN_BRANCH_NAME = "main";
+ /**
+ * The only use of this constant is for applications that were created before SQ 9.8. Sometimes (in example during XML import of
+ * portfolios and applications) we don't have access to default branch name of the application so we default to "master".
+ */
+ public static final String OLD_DEFAULT_MAIN_BRANCH_NAME = "master";
/**
* Maximum length of column "kee"
diff --git a/server/sonar-db-migration/src/main/resources/static/views.xsd b/server/sonar-db-migration/src/main/resources/static/views.xsd
index 952ae224cb3..eee3a8ba3e5 100644
--- a/server/sonar-db-migration/src/main/resources/static/views.xsd
+++ b/server/sonar-db-migration/src/main/resources/static/views.xsd
@@ -22,6 +22,7 @@
<element name="remoteView" maxOccurs="unbounded" minOccurs="0" type="tns:remoteViewType"/>
<element name="vw-ref" maxOccurs="unbounded" minOccurs="0" type="tns:keyType"/>
<element name="qualifier" maxOccurs="1" minOccurs="0" type="string"/>
+ <element name="mainBranch" minOccurs="0" type="tns:mainBranch"/>
<element name="branch" maxOccurs="unbounded" minOccurs="0" type="tns:branchType"/>
<element name="tagsAssociation" maxOccurs="unbounded" minOccurs="0" type="tns:tagsAssociationType"/>
</choice>
@@ -51,6 +52,9 @@
</extension>
</simpleContent>
</complexType>
+ <complexType name="mainBranch">
+ <attribute name="key" type="string" use="required"/>
+ </complexType>
<complexType name="remoteViewType">
<sequence>
<choice minOccurs="1" maxOccurs="unbounded">
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
index edcabaeb833..b64b4ee70db 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
@@ -104,9 +104,8 @@ public class ComponentUpdater {
* - Index component in es indexes
*/
public ComponentDto createApplicationOrPortfolio(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid,
- @Nullable String userLogin) {
- ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userUuid, userLogin,
- defaultBranchNameResolver.getEffectiveMainBranchName(), c -> {});
+ @Nullable String userLogin, @Nullable String mainBranchName) {
+ ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userUuid, userLogin, mainBranchName, c -> {});
commitAndIndex(dbSession, componentDto);
return componentDto;
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java
index 1c16cdbd0e5..a2b789ca7f5 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java
@@ -340,7 +340,7 @@ public class ComponentUpdaterTest {
public void createApplicationOrPortfolio_createsComponentWithMasterBranchName() {
String componentNameAndKey = "createApplicationOrPortfolio";
ComponentDto app = underTest.createApplicationOrPortfolio(db.getSession(),
- NewComponent.newComponentBuilder().setName(componentNameAndKey).setKey(componentNameAndKey).setQualifier("APP").build(), null, null);
+ NewComponent.newComponentBuilder().setName(componentNameAndKey).setKey(componentNameAndKey).setQualifier("APP").build(), null, null, null);
Optional<BranchDto> branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), app.branchUuid());
assertThat(branch).isPresent();