"project_alm_settings",
"project_badge_token",
"project_branches",
+ "project_dependencies",
"project_links",
"project_measures",
"project_qprofiles",
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.dependency;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import javax.annotation.Nullable;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.db.Pagination;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class ProjectDependenciesDaoIT {
+
+ private static final String PROJECT_BRANCH_UUID = "branchUuid";
+
+ @RegisterExtension
+ private final DbTester db = DbTester.create(System2.INSTANCE);
+
+ private final ProjectDependenciesDao projectDependenciesDao = db.getDbClient().projectDependenciesDao();
+
+ @Test
+ void insert_shouldPersistProjectDependencies() {
+ var projectDependencyDto = new ProjectDependencyDto("projectUuid", "version", "includePaths", "packageManager", 1L, 2L);
+
+ projectDependenciesDao.insert(db.getSession(), projectDependencyDto);
+
+ List<Map<String, Object>> select = db.select(db.getSession(), "select * from project_dependencies");
+ assertThat(select).hasSize(1);
+ Map<String, Object> stringObjectMap = select.get(0);
+ assertThat(stringObjectMap).containsExactlyInAnyOrderEntriesOf(
+ Map.of(
+ "uuid", projectDependencyDto.uuid(),
+ "version", projectDependencyDto.version(),
+ "include_paths", projectDependencyDto.includePaths(),
+ "package_manager", projectDependencyDto.packageManager(),
+ "created_at", projectDependencyDto.createdAt(),
+ "updated_at", projectDependencyDto.updatedAt())
+ );
+ }
+
+ @Test
+ void deleteByUuid_shoudDeleteProjectDependencies() {
+ var projectDependencyDto = new ProjectDependencyDto("projectUuid", "version", "includePaths", "packageManager", 1L, 2L);
+ projectDependenciesDao.insert(db.getSession(), projectDependencyDto);
+
+ projectDependenciesDao.deleteByUuid(db.getSession(), projectDependencyDto.uuid());
+
+ List<Map<String, Object>> select = db.select(db.getSession(), "select * from project_dependencies");
+ assertThat(select).isEmpty();
+ }
+
+ @Test
+ void selectByQuery_shouldReturnProjectDependencies_whenQueryByBranchUuid() {
+ ProjectData projectData = db.components().insertPublicProject();
+ var projectDependencyDto = new ProjectDependencyDto(projectData.getMainBranchComponent().uuid(), "version", "includePaths", "packageManager", 1L, 2L);
+ projectDependenciesDao.insert(db.getSession(), projectDependencyDto);
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(projectData.mainBranchUuid(), null);
+ List<ProjectDependencyDto> results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.all());
+
+ assertThat(results).hasSize(1);
+ assertThat(results.get(0)).usingRecursiveComparison().isEqualTo(projectDependencyDto);
+ }
+
+ @Test
+ void selectByQuery_shouldReturnPaginatedProjectDependencies() {
+ ProjectDependencyDto projectDependencyDto1 = insertProjectDependency("1");
+ ProjectDependencyDto projectDependencyDto2 = insertProjectDependency("2");
+ ProjectDependencyDto projectDependencyDto3 = insertProjectDependency("3");
+ ProjectDependencyDto projectDependencyDto4 = insertProjectDependency("4");
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, null);
+ List<ProjectDependencyDto> page1Results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.forPage(1).andSize(2));
+ List<ProjectDependencyDto> page2Results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.forPage(2).andSize(2));
+
+ assertThat(page1Results).hasSize(2);
+ assertThat(page1Results.get(0)).usingRecursiveComparison().isEqualTo(projectDependencyDto1);
+ assertThat(page1Results.get(1)).usingRecursiveComparison().isEqualTo(projectDependencyDto2);
+ assertThat(page2Results).hasSize(2);
+ assertThat(page2Results.get(0)).usingRecursiveComparison().isEqualTo(projectDependencyDto3);
+ assertThat(page2Results.get(1)).usingRecursiveComparison().isEqualTo(projectDependencyDto4);
+ }
+
+ @Test
+ void selectByQuery_shouldPartiallyMatchLongName_whenQueriedByText() {
+ ProjectDependencyDto projectDepSearched = insertProjectDependency("sEArched");
+ insertProjectDependency("notWanted");
+ ProjectDependencyDto projectDepSearchAsWell = insertProjectDependency("sEArchedAsWell");
+ insertProjectDependency("notwantedeither");
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, "long_nameSearCHed");
+ List<ProjectDependencyDto> results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.all());
+
+ assertThat(results).hasSize(2);
+ assertThat(results.get(0)).usingRecursiveComparison().isEqualTo(projectDepSearched);
+ assertThat(results.get(1)).usingRecursiveComparison().isEqualTo(projectDepSearchAsWell);
+ }
+
+ @Test
+ void selectByQuery_shouldExactlyMatchKee_whenQueriedByText() {
+ ProjectDependencyDto projectDepSearched = insertProjectDependency("1", dto -> dto.setKey("keySearched"));
+ insertProjectDependency("2", dto -> dto.setKey("KEySearCHed"));
+ insertProjectDependency("3", dto -> dto.setKey("some_keySearched"));
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, "keySearched");
+ List<ProjectDependencyDto> results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.all());
+
+ assertThat(results).hasSize(1);
+ assertThat(results.get(0)).usingRecursiveComparison().isEqualTo(projectDepSearched);
+ }
+
+ @Test
+ void update_shouldUpdateProjectDependency() {
+ ProjectDependencyDto projectDependencyDto = insertProjectDependency();
+ ProjectDependencyDto updatedProjectDependency =
+ new ProjectDependencyDto(projectDependencyDto.uuid(), "updatedVersion", "updatedIncludePaths", "updatedPackageManager", 2L, 3L);
+
+ projectDependenciesDao.update(db.getSession(), updatedProjectDependency);
+
+ List<Map<String, Object>> select = db.select(db.getSession(), "select * from project_dependencies");
+ assertThat(select).hasSize(1);
+ Map<String, Object> stringObjectMap = select.get(0);
+ assertThat(stringObjectMap).containsExactlyInAnyOrderEntriesOf(
+ Map.of(
+ "uuid", updatedProjectDependency.uuid(),
+ "version", updatedProjectDependency.version(),
+ "include_paths", updatedProjectDependency.includePaths(),
+ "package_manager", updatedProjectDependency.packageManager(),
+ "created_at", projectDependencyDto.createdAt(),
+ "updated_at", updatedProjectDependency.updatedAt())
+ );
+ }
+
+ @Test
+ void countByQuery_shouldReturnTheTotalOfDependencies() {
+ insertProjectDependency("sEArched");
+ insertProjectDependency("notWanted");
+ insertProjectDependency("sEArchedAsWell");
+ db.projectDependencies().insertProjectDependency("another_branch_uuid", "searched");
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, "long_nameSearCHed");
+
+ assertThat(projectDependenciesDao.countByQuery(db.getSession(), projectDependenciesQuery)).isEqualTo(2);
+ assertThat(projectDependenciesDao.countByQuery(db.getSession(), new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, null))).isEqualTo(3);
+ assertThat(projectDependenciesDao.countByQuery(db.getSession(), new ProjectDependenciesQuery("another_branch_uuid", null))).isEqualTo(1);
+ }
+
+ private ProjectDependencyDto insertProjectDependency() {
+ return db.projectDependencies().insertProjectDependency(PROJECT_BRANCH_UUID);
+ }
+
+ private ProjectDependencyDto insertProjectDependency(String suffix) {
+ return insertProjectDependency(suffix, null);
+ }
+
+ private ProjectDependencyDto insertProjectDependency(String suffix, @Nullable Consumer<ComponentDto> dtoPopulator) {
+ return db.projectDependencies().insertProjectDependency(PROJECT_BRANCH_UUID, suffix, dtoPopulator);
+ }
+}
import org.sonar.db.dependency.CveCweDao;
import org.sonar.db.dependency.CveDao;
import org.sonar.db.dependency.IssuesDependencyDao;
+import org.sonar.db.dependency.ProjectDependenciesDao;
import org.sonar.db.duplication.DuplicationDao;
import org.sonar.db.entity.EntityDao;
import org.sonar.db.es.EsQueueDao;
PluginDao.class,
ProjectDao.class,
ProjectBadgeTokenDao.class,
+ ProjectDependenciesDao.class,
ProjectExportDao.class,
PortfolioDao.class,
ProjectLinkDao.class,
import org.sonar.db.dependency.CveCweDao;
import org.sonar.db.dependency.CveDao;
import org.sonar.db.dependency.IssuesDependencyDao;
+import org.sonar.db.dependency.ProjectDependenciesDao;
import org.sonar.db.duplication.DuplicationDao;
import org.sonar.db.entity.EntityDao;
import org.sonar.db.es.EsQueueDao;
private final CveDao cveDao;
private final CveCweDao cveCweDao;
private final IssuesDependencyDao issuesDependencyDao;
+ private final ProjectDependenciesDao projectDependenciesDao;
public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) {
this.database = database;
cveDao = getDao(map, CveDao.class);
cveCweDao = getDao(map, CveCweDao.class);
issuesDependencyDao = getDao(map, IssuesDependencyDao.class);
+ projectDependenciesDao = getDao(map, ProjectDependenciesDao.class);
}
public DbSession openSession(boolean batch) {
public IssuesDependencyDao issuesDependencyDao() {
return issuesDependencyDao;
}
+
+ public ProjectDependenciesDao projectDependenciesDao() {
+ return projectDependenciesDao;
+ }
}
import org.sonar.db.dependency.CveMapper;
import org.sonar.db.dependency.IssuesDependencyDto;
import org.sonar.db.dependency.IssuesDependencyMapper;
+import org.sonar.db.dependency.ProjectDependenciesMapper;
+import org.sonar.db.dependency.ProjectDependencyDto;
import org.sonar.db.duplication.DuplicationMapper;
import org.sonar.db.duplication.DuplicationUnitDto;
import org.sonar.db.entity.EntityDto;
confBuilder.loadAlias("ProjectQgateAssociation", ProjectQgateAssociationDto.class);
confBuilder.loadAlias("Project", ProjectDto.class);
confBuilder.loadAlias("ProjectBadgeToken", ProjectBadgeTokenDto.class);
+ confBuilder.loadAlias("ProjectDependency", ProjectDependencyDto.class);
confBuilder.loadAlias("AnalysisPropertyValuePerProject", AnalysisPropertyValuePerProject.class);
confBuilder.loadAlias("ProjectAlmKeyAndProject", ProjectAlmKeyAndProject.class);
confBuilder.loadAlias("PrAndBranchCountByProjectDto", PrBranchAnalyzedLanguageCountByProjectDto.class);
PluginMapper.class,
PortfolioMapper.class,
ProjectAlmSettingMapper.class,
+ ProjectDependenciesMapper.class,
ProjectLinkMapper.class,
ProjectMapper.class,
ProjectBadgeTokenMapper.class,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.dependency;
+
+import java.util.List;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+import org.sonar.db.Pagination;
+
+public class ProjectDependenciesDao implements Dao {
+
+ private static ProjectDependenciesMapper mapper(DbSession session) {
+ return session.getMapper(ProjectDependenciesMapper.class);
+ }
+
+ public void insert(DbSession session, ProjectDependencyDto projectDependencyDto) {
+ mapper(session).insert(projectDependencyDto);
+ }
+
+ public void deleteByUuid(DbSession session, String uuid) {
+ mapper(session).deleteByUuid(uuid);
+ }
+
+ public List<ProjectDependencyDto> selectByQuery(DbSession session, ProjectDependenciesQuery projectDependenciesQuery, Pagination pagination) {
+ return mapper(session).selectByQuery(projectDependenciesQuery, pagination);
+ }
+
+ public int countByQuery(DbSession session, ProjectDependenciesQuery projectDependenciesQuery) {
+ return mapper(session).countByQuery(projectDependenciesQuery);
+ }
+
+ public void update(DbSession session, ProjectDependencyDto projectDependencyDto) {
+ mapper(session).update(projectDependencyDto);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.dependency;
+
+import java.util.List;
+import org.apache.ibatis.annotations.Param;
+import org.sonar.db.Pagination;
+
+public interface ProjectDependenciesMapper {
+ void insert(ProjectDependencyDto dto);
+
+ void deleteByUuid(String uuid);
+
+ List<ProjectDependencyDto> selectByQuery(@Param("query") ProjectDependenciesQuery query, @Param("pagination") Pagination pagination);
+
+ void update(ProjectDependencyDto dto);
+
+ int countByQuery(@Param("query") ProjectDependenciesQuery query);
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.dependency;
+
+import java.util.Locale;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static org.sonar.db.DaoUtils.buildLikeValue;
+import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER;
+
+public final class ProjectDependenciesQuery {
+ private final String branchUuid;
+ @Nullable
+ private final String query;
+
+ public ProjectDependenciesQuery(String branchUuid, @Nullable String query) {
+ this.branchUuid = branchUuid;
+ this.query = query;
+ }
+
+ /**
+ * Used by MyBatis mapper
+ */
+ @CheckForNull
+ public String getLikeQuery() {
+ return query == null ? null : buildLikeValue(query, BEFORE_AND_AFTER).toLowerCase(Locale.ENGLISH);
+ }
+
+ public String branchUuid() {
+ return branchUuid;
+ }
+
+ @Nullable
+ public String query() {
+ return query;
+ }
+
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.dependency;
+
+import javax.annotation.Nullable;
+
+public record ProjectDependencyDto(
+ String uuid,
+ @Nullable String version,
+ @Nullable String includePaths,
+ @Nullable String packageManager,
+ Long createdAt,
+ Long updatedAt
+ ) {
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
+<mapper namespace="org.sonar.db.dependency.ProjectDependenciesMapper">
+ <sql id="projectDependenciesColumns">
+ pd.uuid as uuid,
+ pd.version as version,
+ pd.include_paths as includePaths,
+ pd.package_manager as packageManager,
+ pd.created_at as createdAt,
+ pd.updated_at as updatedAt
+ </sql>
+
+ <insert id="insert" parameterType="ProjectDependency" useGeneratedKeys="false">
+ insert into project_dependencies (
+ uuid,
+ version,
+ include_paths,
+ package_manager,
+ created_at,
+ updated_at
+ ) values (
+ #{uuid,jdbcType=VARCHAR},
+ #{version,jdbcType=CLOB},
+ #{includePaths,jdbcType=CLOB},
+ #{packageManager,jdbcType=VARCHAR},
+ #{createdAt,jdbcType=BIGINT},
+ #{updatedAt,jdbcType=BIGINT}
+ )
+ </insert>
+
+ <delete id="deleteByUuid" parameterType="string">
+ delete from project_dependencies
+ where uuid = #{uuid,jdbcType=VARCHAR}
+ </delete>
+
+ <select id="selectByQuery" parameterType="map" resultType="ProjectDependency">
+ select <include refid="projectDependenciesColumns"/>
+ <include refid="sqlSelectByQuery" />
+ ORDER BY c.kee ASC
+ <include refid="org.sonar.db.common.Common.pagination"/>
+ </select>
+
+ <select id="countByQuery" resultType="int">
+ select count(pd.uuid)
+ <include refid="sqlSelectByQuery" />
+ </select>
+
+ <sql id="sqlSelectByQuery">
+ from project_dependencies pd
+ inner join components c on pd.uuid = c.uuid
+ where c.branch_uuid = #{query.branchUuid,jdbcType=VARCHAR}
+ <if test="query.query() != null">
+ AND (
+ c.kee = #{query.query,jdbcType=VARCHAR}
+ OR lower(c.long_name) LIKE #{query.likeQuery} ESCAPE '/'
+ )
+ </if>
+ </sql>
+
+ <update id="update" parameterType="ProjectDependency" useGeneratedKeys="false">
+ update project_dependencies
+ set
+ uuid = #{uuid, jdbcType=VARCHAR},
+ version = #{version, jdbcType=CLOB},
+ include_paths = #{includePaths, jdbcType=CLOB},
+ package_manager = #{packageManager, jdbcType=VARCHAR},
+ updated_at = #{updatedAt, jdbcType=BIGINT}
+ where
+ uuid = #{uuid, jdbcType=VARCHAR}
+ </update>
+
+</mapper>
CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_PROJECT_BRANCHES" ON "PROJECT_BRANCHES"("BRANCH_TYPE" NULLS FIRST, "PROJECT_UUID" NULLS FIRST, "KEE" NULLS FIRST);
CREATE INDEX "PROJECT_BRANCHES_PROJECT_UUID" ON "PROJECT_BRANCHES"("PROJECT_UUID" NULLS FIRST);
+CREATE TABLE "PROJECT_DEPENDENCIES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "VERSION" CHARACTER LARGE OBJECT,
+ "INCLUDE_PATHS" CHARACTER LARGE OBJECT,
+ "PACKAGE_MANAGER" CHARACTER VARYING(50),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROJECT_DEPENDENCIES" ADD CONSTRAINT "PK_PROJECT_DEPENDENCIES" PRIMARY KEY("UUID");
+
CREATE TABLE "PROJECT_LINKS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ProjectLinkDbTester;
+import org.sonar.db.dependency.ProjectDependenciesDbTester;
import org.sonar.db.event.EventDbTester;
import org.sonar.db.favorite.FavoriteDbTester;
import org.sonar.db.issue.IssueDbTester;
private final AlmPatsDbTester almPatsDbtester;
private final AuditDbTester auditDbTester;
private final AnticipatedTransitionDbTester anticipatedTransitionDbTester;
+ private final ProjectDependenciesDbTester projectDependenciesDbTester;
private DbTester(UuidFactory uuidFactory, System2 system2, @Nullable String schemaPath, AuditPersister auditPersister, MyBatisConfExtension... confExtensions) {
super(TestDbImpl.create(schemaPath, confExtensions));
this.almPatsDbtester = new AlmPatsDbTester(this);
this.auditDbTester = new AuditDbTester(this);
this.anticipatedTransitionDbTester = new AnticipatedTransitionDbTester(this);
+ this.projectDependenciesDbTester = new ProjectDependenciesDbTester(this);
}
public static DbTester create() {
return anticipatedTransitionDbTester;
}
+ public ProjectDependenciesDbTester projectDependencies() {
+ return projectDependenciesDbTester;
+ }
+
@Override
public void afterEach(ExtensionContext context) throws Exception {
after();
import org.sonar.api.utils.System2;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.portfolio.PortfolioDto;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.dependency;
+
+import java.util.function.Consumer;
+import javax.annotation.Nullable;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDto;
+
+import static org.apache.commons.lang3.StringUtils.EMPTY;
+
+public class ProjectDependenciesDbTester {
+ private final DbTester db;
+ private final DbClient dbClient;
+
+ public ProjectDependenciesDbTester(DbTester db) {
+ this.db = db;
+ this.dbClient = db.getDbClient();
+ }
+
+ public ProjectDependencyDto insertProjectDependency(String branchUuid) {
+ return insertProjectDependency(branchUuid, EMPTY, null);
+ }
+
+ public ProjectDependencyDto insertProjectDependency(String branchUuid, String suffix) {
+ return insertProjectDependency(branchUuid, suffix, null);
+ }
+
+ public ProjectDependencyDto insertProjectDependency(String branchUuid, String suffix, @Nullable Consumer<ComponentDto> dtoPopulator) {
+ ComponentDto componentDto = new ComponentDto().setUuid("uuid" + suffix)
+ .setKey("key" + suffix)
+ .setUuidPath("uuidPath" + suffix)
+ .setName("name" + suffix)
+ .setLongName("long_name" + suffix)
+ .setBranchUuid(branchUuid);
+
+ if (dtoPopulator != null) {
+ dtoPopulator.accept(componentDto);
+ }
+
+ db.components().insertComponent(componentDto);
+ var projectDependencyDto = new ProjectDependencyDto(componentDto.uuid(), "version" + suffix, "includePaths" + suffix, "packageManager" + suffix, 1L, 2L);
+ dbClient.projectDependenciesDao().insert(db.getSession(), projectDependencyDto);
+ return projectDependencyDto;
+ }
+}
| project_alm_settings | Integration Squad |
| project_badge_token | Dev and Team Workflow Squad |
| project_branches | |
+| project_dependencies | Analysis Experience Squad |
| project_links | Dev and Team Workflow Squad |
| project_measures | Analysis Experience Squad |
| project_qgates | Dev and Team Workflow Squad |
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v108;
+
+import java.sql.SQLException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.sonar.db.MigrationDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static java.sql.Types.BIGINT;
+import static java.sql.Types.CLOB;
+import static java.sql.Types.VARCHAR;
+import static org.sonar.db.MigrationDbTester.createForMigrationStep;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+
+class CreateProjectDependenciesTableIT {
+
+ private static final String TABLE_NAME = "project_dependencies";
+
+ @RegisterExtension
+ public final MigrationDbTester db = createForMigrationStep(CreateProjectDependenciesTable.class);
+
+ private final DdlChange underTest = new CreateProjectDependenciesTable(db.database());
+
+ @Test
+ void execute_shouldCreateTable() throws SQLException {
+ db.assertTableDoesNotExist(TABLE_NAME);
+
+ underTest.execute();
+
+ db.assertTableExists(TABLE_NAME);
+ db.assertPrimaryKey(TABLE_NAME, "pk_project_dependencies", "uuid");
+ db.assertColumnDefinition(TABLE_NAME, "uuid", VARCHAR, UUID_SIZE, false);
+ db.assertColumnDefinition(TABLE_NAME, "version", CLOB, null, true);
+ db.assertColumnDefinition(TABLE_NAME, "include_paths", CLOB, null, true);
+ db.assertColumnDefinition(TABLE_NAME, "package_manager", VARCHAR, 50, true);
+ db.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, null, false);
+ db.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, null, false);
+ }
+
+ @Test
+ void execute_shouldBeReentrant() throws SQLException {
+ db.assertTableDoesNotExist(TABLE_NAME);
+ underTest.execute();
+
+ underTest.execute();
+
+ db.assertTableExists(TABLE_NAME);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v108;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
+import org.sonar.server.platform.db.migration.step.CreateTableChange;
+
+import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateProjectDependenciesTable extends CreateTableChange {
+
+ private static final String TABLE_NAME = "project_dependencies";
+ private static final String COLUMN_UUID_NAME = "uuid";
+ private static final String COLUMN_VERSION_NAME = "version";
+ private static final String COLUMN_INCLUDE_PATHS_NAME = "include_paths";
+ private static final String COLUMN_PACKAGE_MANAGER_NAME = "package_manager";
+ private static final int COLUMN_PACKAGE_MANAGER_SIZE = 50;
+ private static final String COLUMN_CREATED_AT_NAME = "created_at";
+ private static final String COLUMN_UPDATED_AT_NAME = "updated_at";
+
+ protected CreateProjectDependenciesTable(Database db) {
+ super(db, TABLE_NAME);
+ }
+
+ @Override
+ public void execute(Context context, String tableName) throws SQLException {
+ context.execute(new CreateTableBuilder(getDialect(), tableName)
+ .addPkColumn(newVarcharColumnDefBuilder().setColumnName(COLUMN_UUID_NAME).setIsNullable(false).setLimit(UUID_SIZE).build())
+ .addColumn(newClobColumnDefBuilder().setColumnName(COLUMN_VERSION_NAME).setIsNullable(true).build())
+ .addColumn(newClobColumnDefBuilder().setColumnName(COLUMN_INCLUDE_PATHS_NAME).setIsNullable(true).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName(COLUMN_PACKAGE_MANAGER_NAME).setIsNullable(true).setLimit(COLUMN_PACKAGE_MANAGER_SIZE).build())
+ .addColumn(newBigIntegerColumnDefBuilder().setColumnName(COLUMN_CREATED_AT_NAME).setIsNullable(false).build())
+ .addColumn(newBigIntegerColumnDefBuilder().setColumnName(COLUMN_UPDATED_AT_NAME).setIsNullable(false).build())
+ .build());
+ }
+}
.add(10_8_013, "Drop index on 'project_branches.measures_migrated'", DropIndexOnProjectBranchesMeasuresMigrated.class)
.add(10_8_014, "Drop 'measures_migrated' column on 'project_branches' table", DropMeasuresMigratedColumnInProjectBranchesTable.class)
.add(10_8_015, "Add column 'impacts' in 'active_rules' table", AddImpactsColumnInActiveRulesTable.class)
- ;
+ .add(10_8_016, "Create 'project_dependencies' table", CreateProjectDependenciesTable.class);
}
}