@@ -0,0 +1,74 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.ce.task.projectanalysis.component; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.project.ProjectDto; | |||
/** | |||
* Creates or updates the data in table {@code PROJECTS} for the current root. | |||
*/ | |||
public class ProjectPersister { | |||
private final DbClient dbClient; | |||
private final TreeRootHolder treeRootHolder; | |||
private final System2 system2; | |||
public ProjectPersister(DbClient dbClient, TreeRootHolder treeRootHolder, System2 system2) { | |||
this.dbClient = dbClient; | |||
this.treeRootHolder = treeRootHolder; | |||
this.system2 = system2; | |||
} | |||
public void persist(DbSession dbSession) { | |||
if (shouldSkip(treeRootHolder.getRoot())) { | |||
return; | |||
} | |||
ProjectDto dbProjectDto = dbClient.projectDao().selectProjectByKey(dbSession, treeRootHolder.getRoot().getKey()) | |||
.orElseThrow(() -> new IllegalStateException("Project has been deleted by end-user during analysis")); | |||
ProjectDto projectDto = toProjectDto(treeRootHolder.getRoot()); | |||
if (hasChanged(dbProjectDto, projectDto)) { | |||
// insert or update in projects table | |||
dbClient.projectDao().update(dbSession, projectDto); | |||
} | |||
} | |||
private boolean shouldSkip(Component rootComponent) { | |||
return !rootComponent.getType().equals(Component.Type.PROJECT) && !rootComponent.getType().equals(Component.Type.PROJECT_VIEW); | |||
} | |||
private boolean hasChanged(ProjectDto dbProject, ProjectDto newProject) { | |||
return !StringUtils.equals(dbProject.getName(), newProject.getName()) || | |||
!StringUtils.equals(dbProject.getDescription(), newProject.getDescription()); | |||
} | |||
private ProjectDto toProjectDto(Component root) { | |||
ProjectDto projectDto = new ProjectDto(); | |||
projectDto.setUuid(root.getUuid()); | |||
projectDto.setName(root.getName()); | |||
projectDto.setDescription(root.getDescription()); | |||
projectDto.setUpdatedAt(system2.now()); | |||
return projectDto; | |||
} | |||
} |
@@ -34,6 +34,7 @@ import org.sonar.ce.task.projectanalysis.component.BranchPersisterImpl; | |||
import org.sonar.ce.task.projectanalysis.component.ConfigurationRepositoryImpl; | |||
import org.sonar.ce.task.projectanalysis.component.DbIdsRepositoryImpl; | |||
import org.sonar.ce.task.projectanalysis.component.DisabledComponentsHolderImpl; | |||
import org.sonar.ce.task.projectanalysis.component.ProjectPersister; | |||
import org.sonar.ce.task.projectanalysis.component.ReferenceBranchComponentUuids; | |||
import org.sonar.ce.task.projectanalysis.component.ReportModulesPath; | |||
import org.sonar.ce.task.projectanalysis.component.SiblingComponentsWithOpenIssues; | |||
@@ -284,6 +285,7 @@ public final class ProjectAnalysisTaskContainerPopulator implements ContainerPop | |||
BaseIssuesLoader.class, | |||
IssueTrackingDelegator.class, | |||
BranchPersisterImpl.class, | |||
ProjectPersister.class, | |||
SiblingsIssuesLoader.class, | |||
SiblingsIssueMerger.class, | |||
NewCodePeriodResolver.class, |
@@ -44,6 +44,7 @@ import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHold | |||
import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler; | |||
import org.sonar.ce.task.projectanalysis.component.PathAwareVisitor; | |||
import org.sonar.ce.task.projectanalysis.component.PathAwareVisitorAdapter; | |||
import org.sonar.ce.task.projectanalysis.component.ProjectPersister; | |||
import org.sonar.ce.task.projectanalysis.component.TreeRootHolder; | |||
import org.sonar.ce.task.step.ComputationStep; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
@@ -71,11 +72,12 @@ public class PersistComponentsStep implements ComputationStep { | |||
private final MutableDisabledComponentsHolder disabledComponentsHolder; | |||
private final AnalysisMetadataHolder analysisMetadataHolder; | |||
private final BranchPersister branchPersister; | |||
private final ProjectPersister projectPersister; | |||
public PersistComponentsStep(DbClient dbClient, TreeRootHolder treeRootHolder, | |||
MutableDbIdsRepository dbIdsRepository, System2 system2, | |||
MutableDisabledComponentsHolder disabledComponentsHolder, AnalysisMetadataHolder analysisMetadataHolder, | |||
BranchPersister branchPersister) { | |||
BranchPersister branchPersister, ProjectPersister projectPersister) { | |||
this.dbClient = dbClient; | |||
this.treeRootHolder = treeRootHolder; | |||
this.dbIdsRepository = dbIdsRepository; | |||
@@ -83,6 +85,7 @@ public class PersistComponentsStep implements ComputationStep { | |||
this.disabledComponentsHolder = disabledComponentsHolder; | |||
this.analysisMetadataHolder = analysisMetadataHolder; | |||
this.branchPersister = branchPersister; | |||
this.projectPersister = projectPersister; | |||
} | |||
@Override | |||
@@ -94,6 +97,7 @@ public class PersistComponentsStep implements ComputationStep { | |||
public void execute(ComputationStep.Context context) { | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
branchPersister.persist(dbSession); | |||
projectPersister.persist(dbSession); | |||
String projectUuid = treeRootHolder.getRoot().getUuid(); | |||
@@ -105,7 +105,7 @@ public class BranchPersisterImplTest { | |||
// add project and branch in table PROJECTS | |||
ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getKey()); | |||
ComponentDto component = ComponentTesting.newProjectBranch(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); | |||
ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); | |||
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), mainComponent, component); | |||
dbTester.commit(); | |||
// set project in metadata | |||
@@ -117,7 +117,7 @@ public class BranchPersisterImplTest { | |||
dbTester.getSession().commit(); | |||
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(2); | |||
assertThat(dbTester.countRowsOfTable("components")).isEqualTo(2); | |||
Optional<BranchDto> branchDto = dbTester.getDbClient().branchDao().selectByUuid(dbTester.getSession(), BRANCH1.getUuid()); | |||
assertThat(branchDto).isPresent(); | |||
assertThat(branchDto.get().getBranchType()).isEqualTo(BRANCH); | |||
@@ -131,7 +131,7 @@ public class BranchPersisterImplTest { | |||
public void main_branch_is_excluded_from_branch_purge_by_default() { | |||
analysisMetadataHolder.setBranch(createBranch(BRANCH, true, "master")); | |||
treeRootHolder.setRoot(MAIN); | |||
dbTester.components().insertMainBranch(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); | |||
dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); | |||
dbTester.commit(); | |||
underTest.persist(dbTester.getSession()); | |||
@@ -146,8 +146,8 @@ public class BranchPersisterImplTest { | |||
analysisMetadataHolder.setBranch(createBranch(BRANCH, false, "BRANCH_KEY")); | |||
treeRootHolder.setRoot(BRANCH1); | |||
ComponentDto mainComponent = dbTester.components().insertMainBranch(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); | |||
ComponentDto component = ComponentTesting.newProjectBranch(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); | |||
ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); | |||
ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); | |||
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component); | |||
dbTester.commit(); | |||
@@ -163,8 +163,8 @@ public class BranchPersisterImplTest { | |||
analysisMetadataHolder.setBranch(createBranch(BRANCH, false, "BRANCH_KEY")); | |||
treeRootHolder.setRoot(BRANCH1); | |||
ComponentDto mainComponent = dbTester.components().insertMainBranch(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); | |||
ComponentDto component = ComponentTesting.newProjectBranch(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); | |||
ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); | |||
ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); | |||
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component); | |||
dbTester.commit(); | |||
@@ -188,7 +188,7 @@ public class BranchPersisterImplTest { | |||
// add project and branch in table PROJECTS | |||
ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getKey()); | |||
ComponentDto component = ComponentTesting.newProjectBranch(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(PULL_REQUEST)); | |||
ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(PULL_REQUEST)); | |||
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), mainComponent, component); | |||
dbTester.commit(); | |||
// set project in metadata | |||
@@ -201,7 +201,7 @@ public class BranchPersisterImplTest { | |||
dbTester.getSession().commit(); | |||
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(2); | |||
assertThat(dbTester.countRowsOfTable("components")).isEqualTo(2); | |||
Optional<BranchDto> branchDto = dbTester.getDbClient().branchDao().selectByUuid(dbTester.getSession(), BRANCH1.getUuid()); | |||
assertThat(branchDto).isPresent(); | |||
assertThat(branchDto.get().getBranchType()).isEqualTo(PULL_REQUEST); |
@@ -121,7 +121,7 @@ public class ConfigurationRepositoryTest { | |||
@Test | |||
public void branch_settings() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branchDto = db.components().insertProjectBranch(project); | |||
Branch branch = mock(Branch.class); | |||
when(branch.getName()).thenReturn(branchDto.getBranch()); |
@@ -0,0 +1,115 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.ce.task.projectanalysis.component; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.impl.utils.TestSystem2; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.verifyNoInteractions; | |||
import static org.mockito.Mockito.verifyNoMoreInteractions; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.VIEW; | |||
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder; | |||
public class ProjectPersisterTest { | |||
private final static Component ROOT = builder(PROJECT, 1) | |||
.setUuid("PROJECT_UUID") | |||
.setKey("PROJECT_KEY") | |||
.setDescription("PROJECT_DESC") | |||
.setName("PROJECT_NAME") | |||
.build(); | |||
@Rule | |||
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
@Rule | |||
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); | |||
@Rule | |||
public ExpectedException exception = ExpectedException.none(); | |||
public TestSystem2 system2 = new TestSystem2(); | |||
private ProjectPersister underTest = new ProjectPersister(dbTester.getDbClient(), treeRootHolder, system2); | |||
@Before | |||
public void prepare() { | |||
treeRootHolder.setRoot(ROOT); | |||
system2.setNow(1000L); | |||
} | |||
@Test | |||
public void skip_portfolios() { | |||
Component root = ViewsComponent.builder(VIEW, 1).build(); | |||
TreeRootHolder treeRootHolder = mock(TreeRootHolder.class); | |||
when(treeRootHolder.getRoot()).thenReturn(root); | |||
new ProjectPersister(dbTester.getDbClient(), treeRootHolder, system2).persist(dbTester.getSession()); | |||
verify(treeRootHolder).getRoot(); | |||
verifyNoMoreInteractions(treeRootHolder); | |||
} | |||
@Test | |||
public void update_description() { | |||
ProjectDto p1 = dbTester.components().insertPublicProjectDto(dbTester.getDefaultOrganization(), | |||
c -> c.setUuid("PROJECT_UUID").setDbKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")); | |||
assertProject("OLD_DESC", ROOT.getName(), p1.getUpdatedAt()); | |||
underTest.persist(dbTester.getSession()); | |||
assertProject(ROOT.getDescription(), ROOT.getName(), 1000L); | |||
} | |||
@Test | |||
public void update_name() { | |||
ProjectDto p1 = dbTester.components().insertPublicProjectDto(dbTester.getDefaultOrganization(), | |||
c -> c.setUuid("PROJECT_UUID").setDbKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())); | |||
assertProject(ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt()); | |||
underTest.persist(dbTester.getSession()); | |||
assertProject(ROOT.getDescription(), ROOT.getName(), 1000L); | |||
} | |||
@Test | |||
public void dont_update() { | |||
ProjectDto p1 = dbTester.components().insertPublicProjectDto(dbTester.getDefaultOrganization(), | |||
c -> c.setUuid("PROJECT_UUID").setDbKey(ROOT.getKey()).setName(ROOT.getName()).setDescription(ROOT.getDescription())); | |||
assertProject(ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt()); | |||
underTest.persist(dbTester.getSession()); | |||
assertProject(ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt()); | |||
} | |||
private void assertProject(String description, String name, long updated) { | |||
assertThat(dbTester.getDbClient().projectDao().selectProjectByKey(dbTester.getSession(), ROOT.getKey()).get()) | |||
.extracting(ProjectDto::getName, ProjectDto::getDescription, ProjectDto::getUpdatedAt) | |||
.containsExactly(name, description, updated); | |||
} | |||
} |
@@ -62,7 +62,7 @@ public class ReferenceBranchComponentUuidsTest { | |||
analysisMetadataHolder.setProject(project); | |||
analysisMetadataHolder.setBranch(branch); | |||
ComponentDto projectDto = db.components().insertMainBranch(); | |||
ComponentDto projectDto = db.components().insertPublicProject(); | |||
when(project.getUuid()).thenReturn(projectDto.uuid()); | |||
branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch1")); | |||
branch2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch2")); |
@@ -63,7 +63,7 @@ public class SiblingComponentsWithOpenIssuesTest { | |||
@Before | |||
public void setUp() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
branch1 = db.components().insertProjectBranch(project, b -> b.setKey("branch1"), b -> b.setBranchType(BranchType.BRANCH)); | |||
branch1pr1 = db.components().insertProjectBranch(project, | |||
@@ -157,7 +157,7 @@ public class SiblingComponentsWithOpenIssuesTest { | |||
@Test | |||
public void should_find_sibling_components_with_open_issues_from_pullrequest() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
setRoot(project); | |||
setBranch(BranchType.BRANCH); | |||
@@ -176,7 +176,7 @@ public class SiblingComponentsWithOpenIssuesTest { | |||
@Test | |||
public void should_not_find_sibling_components_on_derived_branch() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
setRoot(project); | |||
setBranch(BranchType.BRANCH); | |||
@@ -74,7 +74,7 @@ public class ProjectTrackerBaseLazyInputTest { | |||
public void prepare() { | |||
rule = dbTester.rules().insert(); | |||
ruleRepositoryRule.add(rule.getKey()); | |||
rootProjectDto = dbTester.components().insertMainBranch(); | |||
rootProjectDto = dbTester.components().insertPublicProject(); | |||
ReportComponent rootProject = ReportComponent.builder(Component.Type.FILE, 1) | |||
.setKey(rootProjectDto.getDbKey()) | |||
.setUuid(rootProjectDto.uuid()).build(); |
@@ -109,7 +109,7 @@ public class SiblingsIssueMergerTest { | |||
copier = new SiblingsIssueMerger(new SiblingsIssuesLoader(new SiblingComponentsWithOpenIssues(treeRootHolder, metadataHolder, dbClient), dbClient, componentIssuesLoader), | |||
tracker, | |||
issueLifecycle); | |||
projectDto = db.components().insertMainBranch(p -> p.setDbKey(PROJECT_KEY).setUuid(PROJECT_UUID)); | |||
projectDto = db.components().insertPublicProject(p -> p.setDbKey(PROJECT_KEY).setUuid(PROJECT_UUID)); | |||
branch1Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch1") | |||
.setBranchType(BranchType.PULL_REQUEST) | |||
.setMergeBranchUuid(projectDto.uuid())); |
@@ -196,7 +196,7 @@ public class BuildComponentTreeStepTest { | |||
@Test | |||
public void generate_keys_when_using_existing_branch() { | |||
ComponentDto projectDto = dbTester.components().insertMainBranch(); | |||
ComponentDto projectDto = dbTester.components().insertPublicProject(); | |||
ComponentDto branchDto = dbTester.components().insertProjectBranch(projectDto); | |||
Branch branch = mock(Branch.class); | |||
when(branch.getName()).thenReturn(branchDto.getBranch()); |
@@ -103,7 +103,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
@Before | |||
public void setUp() { | |||
organization = dbTester.organizations().insert(); | |||
project = dbTester.components().insertMainBranch(organization); | |||
project = dbTester.components().insertPublicProject(organization); | |||
when(analysisMetadataHolder.isBranch()).thenReturn(true); | |||
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | |||
@@ -241,7 +241,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
@Test | |||
public void throw_ISE_when_specific_analysis_is_set_but_does_not_exist_in_DB() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
ComponentDto project = dbTester.components().insertPublicProject(organization); | |||
setProjectPeriod(project.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "nonexistent"); | |||
setupRoot(project); | |||
@@ -253,7 +253,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
@Test | |||
public void throw_ISE_when_specific_analysis_is_set_but_does_not_belong_to_current_project() { | |||
ComponentDto otherProject = dbTester.components().insertMainBranch(organization); | |||
ComponentDto otherProject = dbTester.components().insertPublicProject(organization); | |||
SnapshotDto otherProjectAnalysis = dbTester.components().insertSnapshot(otherProject); | |||
setBranchPeriod(project.uuid(), project.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, otherProjectAnalysis.getUuid()); | |||
setupRoot(project); |
@@ -28,6 +28,7 @@ import org.sonar.ce.task.projectanalysis.component.BranchPersister; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.MutableDbIdsRepository; | |||
import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHolder; | |||
import org.sonar.ce.task.projectanalysis.component.ProjectPersister; | |||
import org.sonar.ce.task.projectanalysis.component.TreeRootHolder; | |||
import org.sonar.ce.task.step.TestComputationStepContext; | |||
import org.sonar.db.DbClient; | |||
@@ -69,6 +70,7 @@ public class PersistComponentsStepTest { | |||
System2.INSTANCE, | |||
mock(MutableDisabledComponentsHolder.class), | |||
mock(AnalysisMetadataHolder.class), | |||
mock(BranchPersister.class)).execute(new TestComputationStepContext()); | |||
mock(BranchPersister.class), | |||
mock(ProjectPersister.class)).execute(new TestComputationStepContext()); | |||
} | |||
} |
@@ -38,6 +38,7 @@ import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl; | |||
import org.sonar.ce.task.projectanalysis.component.FileAttributes; | |||
import org.sonar.ce.task.projectanalysis.component.MutableDbIdsRepositoryRule; | |||
import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHolder; | |||
import org.sonar.ce.task.projectanalysis.component.ProjectPersister; | |||
import org.sonar.ce.task.projectanalysis.component.ReportComponent; | |||
import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; | |||
import org.sonar.ce.task.step.ComputationStep; | |||
@@ -95,7 +96,8 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
db.organizations().insertForUuid(ORGANIZATION_UUID); | |||
BranchPersister branchPersister = mock(BranchPersister.class); | |||
underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister); | |||
ProjectPersister projectPersister = mock(ProjectPersister.class); | |||
underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister); | |||
} | |||
@Override | |||
@@ -123,7 +125,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(db.countRowsOfTable("projects")).isEqualTo(3); | |||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | |||
ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); | |||
assertThat(directoryDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); | |||
@@ -185,7 +187,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(db.countRowsOfTable("projects")).isEqualTo(3); | |||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | |||
ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); | |||
assertThat(directoryDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); | |||
@@ -365,7 +367,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(db.countRowsOfTable("projects")).isEqualTo(3); | |||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | |||
ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get(); | |||
assertThat(projectReloaded.getId()).isEqualTo(project.getId()); | |||
@@ -414,7 +416,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(db.countRowsOfTable("projects")).isEqualTo(3); | |||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | |||
assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().getId()).isEqualTo(project.getId()); | |||
assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().getId()).isEqualTo(directory.getId()); | |||
assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().getId()).isEqualTo(file.getId()); | |||
@@ -476,7 +478,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid()); | |||
db.commit(); | |||
assertThat(db.countRowsOfTable("projects")).isEqualTo(3); | |||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | |||
ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); | |||
assertThat(directoryReloaded).isNotNull(); | |||
@@ -548,7 +550,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(db.countRowsOfTable("projects")).isEqualTo(3); | |||
assertThat(db.countRowsOfTable("components")).isEqualTo(3); | |||
assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().getId()).isEqualTo(project.getId()); | |||
assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().getId()).isEqualTo(removedDirectory.getId()); | |||
assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().getId()).isEqualTo(removedFile.getId()); |
@@ -101,7 +101,7 @@ import static org.sonar.db.component.BranchType.PULL_REQUEST; | |||
import static org.sonar.db.component.ComponentTesting.newBranchDto; | |||
import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; | |||
import static org.sonar.db.component.ComponentTesting.newProjectBranch; | |||
import static org.sonar.db.component.ComponentTesting.newBranchComponent; | |||
import static org.sonar.db.issue.IssueTesting.newIssue; | |||
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; | |||
import static org.sonar.db.rule.RuleTesting.newRule; | |||
@@ -560,7 +560,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
private void sendIssueChangeNotificationOnBranch(long issueCreatedAt) { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto branch = newProjectBranch(project, newBranchDto(project).setKey(BRANCH_NAME)); | |||
ComponentDto branch = newBranchComponent(project, newBranchDto(project).setKey(BRANCH_NAME)); | |||
ComponentDto file = newFileDto(branch); | |||
treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( | |||
builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build()); | |||
@@ -692,7 +692,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
} | |||
private ComponentDto setUpBranch(ComponentDto project, BranchType branchType) { | |||
ComponentDto branch = newProjectBranch(project, newBranchDto(project, branchType).setKey(BRANCH_NAME)); | |||
ComponentDto branch = newBranchComponent(project, newBranchDto(project, branchType).setKey(BRANCH_NAME)); | |||
ComponentDto file = newFileDto(branch); | |||
treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( | |||
builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build()); |
@@ -69,7 +69,7 @@ public class ValidateProjectStepTest { | |||
@Test | |||
public void fail_if_pr_is_targeting_branch_with_modules() { | |||
ComponentDto masterProject = dbTester.components().insertMainBranch(); | |||
ComponentDto masterProject = dbTester.components().insertPublicProject(); | |||
ComponentDto mergeBranch = dbTester.components().insertProjectBranch(masterProject, b -> b.setKey("mergeBranch")); | |||
dbClient.componentDao().insert(dbTester.getSession(), ComponentTesting.newModuleDto(mergeBranch)); | |||
setBranch(BranchType.PULL_REQUEST, mergeBranch.uuid()); | |||
@@ -86,7 +86,7 @@ public class ValidateProjectStepTest { | |||
@Test | |||
public void dont_fail_for_long_forked_from_master_with_modules() { | |||
ComponentDto masterProject = dbTester.components().insertMainBranch(); | |||
ComponentDto masterProject = dbTester.components().insertPublicProject(); | |||
dbClient.componentDao().insert(dbTester.getSession(), ComponentTesting.newModuleDto(masterProject)); | |||
setBranch(BranchType.BRANCH, masterProject.uuid()); | |||
dbTester.getSession().commit(); |
@@ -36,6 +36,7 @@ import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl; | |||
import org.sonar.ce.task.projectanalysis.component.MutableDbIdsRepositoryRule; | |||
import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHolder; | |||
import org.sonar.ce.task.projectanalysis.component.ProjectPersister; | |||
import org.sonar.ce.task.projectanalysis.component.ProjectViewAttributes; | |||
import org.sonar.ce.task.projectanalysis.component.SubViewAttributes; | |||
import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; | |||
@@ -104,7 +105,8 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
dbTester.organizations().insertForUuid(ORGANIZATION_UUID); | |||
analysisMetadataHolder.setBranch(new DefaultBranchImpl()); | |||
BranchPersister branchPersister = mock(BranchPersister.class); | |||
underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister); | |||
ProjectPersister projectPersister = mock(ProjectPersister.class); | |||
underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister); | |||
} | |||
@Override | |||
@@ -482,7 +484,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
} | |||
private void assertRowsCountInTableProjects(int rowCount) { | |||
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(rowCount); | |||
assertThat(dbTester.countRowsOfTable("components")).isEqualTo(rowCount); | |||
} | |||
private void assertDtoNotUpdated(String componentKey) { |
@@ -128,7 +128,7 @@ public class ComputeEngineContainerImplTest { | |||
assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize( | |||
COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION | |||
+ 27 // level 1 | |||
+ 65 // content of DaoModule | |||
+ 66 // content of DaoModule | |||
+ 3 // content of EsModule | |||
+ 50 // content of CorePropertyDefinitions | |||
+ 1 // StopFlagContainer |
@@ -61,6 +61,7 @@ public final class SqTables { | |||
"ce_task_input", | |||
"ce_task_message", | |||
"ce_scanner_context", | |||
"components", | |||
"default_qprofiles", | |||
"deprecated_rule_keys", | |||
"duplications_index", |
@@ -61,6 +61,7 @@ import org.sonar.db.permission.UserPermissionDao; | |||
import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao; | |||
import org.sonar.db.permission.template.PermissionTemplateDao; | |||
import org.sonar.db.plugin.PluginDao; | |||
import org.sonar.db.project.ProjectDao; | |||
import org.sonar.db.property.InternalComponentPropertiesDao; | |||
import org.sonar.db.property.InternalPropertiesDao; | |||
import org.sonar.db.property.PropertiesDao; | |||
@@ -135,6 +136,7 @@ public class DaoModule extends Module { | |||
PermissionTemplateCharacteristicDao.class, | |||
PermissionTemplateDao.class, | |||
PluginDao.class, | |||
ProjectDao.class, | |||
ProjectLinkDao.class, | |||
ProjectMappingsDao.class, | |||
ProjectQgateAssociationDao.class, |
@@ -59,6 +59,7 @@ import org.sonar.db.permission.UserPermissionDao; | |||
import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao; | |||
import org.sonar.db.permission.template.PermissionTemplateDao; | |||
import org.sonar.db.plugin.PluginDao; | |||
import org.sonar.db.project.ProjectDao; | |||
import org.sonar.db.property.InternalComponentPropertiesDao; | |||
import org.sonar.db.property.InternalPropertiesDao; | |||
import org.sonar.db.property.PropertiesDao; | |||
@@ -158,6 +159,7 @@ public class DbClient { | |||
private final ProjectMappingsDao projectMappingsDao; | |||
private final OrganizationAlmBindingDao organizationAlmBindingDao; | |||
private final NewCodePeriodDao newCodePeriodDao; | |||
private final ProjectDao projectDao; | |||
public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) { | |||
this.database = database; | |||
@@ -233,6 +235,7 @@ public class DbClient { | |||
organizationAlmBindingDao = getDao(map, OrganizationAlmBindingDao.class); | |||
internalComponentPropertiesDao = getDao(map, InternalComponentPropertiesDao.class); | |||
newCodePeriodDao = getDao(map, NewCodePeriodDao.class); | |||
projectDao = getDao(map, ProjectDao.class); | |||
} | |||
public DbSession openSession(boolean batch) { | |||
@@ -311,6 +314,10 @@ public class DbClient { | |||
return componentDao; | |||
} | |||
public ProjectDao projectDao() { | |||
return projectDao; | |||
} | |||
public ComponentKeyUpdaterDao componentKeyUpdaterDao() { | |||
return componentKeyUpdaterDao; | |||
} |
@@ -102,6 +102,8 @@ import org.sonar.db.permission.template.PermissionTemplateMapper; | |||
import org.sonar.db.permission.template.PermissionTemplateUserDto; | |||
import org.sonar.db.plugin.PluginDto; | |||
import org.sonar.db.plugin.PluginMapper; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.project.ProjectMapper; | |||
import org.sonar.db.property.InternalComponentPropertiesMapper; | |||
import org.sonar.db.property.InternalComponentPropertyDto; | |||
import org.sonar.db.property.InternalPropertiesMapper; | |||
@@ -202,6 +204,7 @@ public class MyBatis implements Startable { | |||
confBuilder.loadAlias("PrIssue", PrIssueDto.class); | |||
confBuilder.loadAlias("ProjectAlmBinding", ProjectAlmBindingDto.class); | |||
confBuilder.loadAlias("ProjectQgateAssociation", ProjectQgateAssociationDto.class); | |||
confBuilder.loadAlias("Project", ProjectDto.class); | |||
confBuilder.loadAlias("ProjectMapping", ProjectMappingDto.class); | |||
confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class); | |||
confBuilder.loadAlias("QualityGateCondition", QualityGateConditionDto.class); | |||
@@ -267,6 +270,7 @@ public class MyBatis implements Startable { | |||
ProjectAlmBindingMapper.class, | |||
ProjectAlmSettingMapper.class, | |||
ProjectLinkMapper.class, | |||
ProjectMapper.class, | |||
ProjectMappingsMapper.class, | |||
ProjectQgateAssociationMapper.class, | |||
PropertiesMapper.class, |
@@ -25,6 +25,7 @@ import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.Dao; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.project.ProjectDto; | |||
public class ProjectAlmSettingDao implements Dao { | |||
@@ -49,8 +50,8 @@ public class ProjectAlmSettingDao implements Dao { | |||
projectAlmSettingDto.setUpdatedAt(now); | |||
} | |||
public void deleteByProject(DbSession dbSession, ComponentDto project) { | |||
getMapper(dbSession).deleteByProjectUuid(project.uuid()); | |||
public void deleteByProject(DbSession dbSession, ProjectDto project) { | |||
getMapper(dbSession).deleteByProjectUuid(project.getUuid()); | |||
} | |||
public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) { | |||
@@ -61,8 +62,8 @@ public class ProjectAlmSettingDao implements Dao { | |||
return getMapper(dbSession).countByAlmSettingUuid(almSetting.getUuid()); | |||
} | |||
public Optional<ProjectAlmSettingDto> selectByProject(DbSession dbSession, ComponentDto project) { | |||
return selectByProject(dbSession, project.uuid()); | |||
public Optional<ProjectAlmSettingDto> selectByProject(DbSession dbSession, ProjectDto project) { | |||
return selectByProject(dbSession, project.getUuid()); | |||
} | |||
public Optional<ProjectAlmSettingDto> selectByProject(DbSession dbSession, String projectUuid) { |
@@ -20,11 +20,14 @@ | |||
package org.sonar.db.component; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.Dao; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.sonar.db.DatabaseUtils.executeLargeInputs; | |||
@@ -72,6 +75,13 @@ public class BranchDao implements Dao { | |||
return selectByKey(dbSession, projectUuid, key, KeyType.BRANCH); | |||
} | |||
public List<BranchDto> selectByBranchKeys(DbSession dbSession, Map<String, String> branchKeyByProjectUuid) { | |||
if (branchKeyByProjectUuid.isEmpty()) { | |||
return Collections.emptyList(); | |||
} | |||
return mapper(dbSession).selectByBranchKeys(branchKeyByProjectUuid); | |||
} | |||
public Optional<BranchDto> selectByPullRequestKey(DbSession dbSession, String projectUuid, String key) { | |||
return selectByKey(dbSession, projectUuid, key, KeyType.PULL_REQUEST); | |||
} | |||
@@ -88,6 +98,10 @@ public class BranchDao implements Dao { | |||
return mapper(dbSession).selectByProjectUuid(projectUuid); | |||
} | |||
public Collection<BranchDto> selectByProject(DbSession dbSession, ProjectDto project) { | |||
return mapper(dbSession).selectByProjectUuid(project.getUuid()); | |||
} | |||
public List<BranchDto> selectByUuids(DbSession session, Collection<String> uuids) { | |||
return executeLargeInputs(uuids, mapper(session)::selectByUuids); | |||
} |
@@ -21,8 +21,10 @@ package org.sonar.db.component; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import java.util.Map; | |||
import javax.annotation.Nullable; | |||
import org.apache.ibatis.annotations.Param; | |||
import org.sonar.db.DbSession; | |||
public interface BranchMapper { | |||
@@ -43,6 +45,8 @@ public interface BranchMapper { | |||
Collection<BranchDto> selectByProjectUuid(@Param("projectUuid") String projectUuid); | |||
List<BranchDto> selectByBranchKeys(@Param("branchKeyByProjectUuid") Map<String, String> branchKeyByProjectUuid); | |||
List<BranchDto> selectByUuids(@Param("uuids") Collection<String> uuids); | |||
long countNonMainBranches(); |
@@ -73,14 +73,6 @@ public class ComponentDao implements Dao { | |||
return mapper(session).countByQuery(organizationUuid, query); | |||
} | |||
@CheckForNull | |||
private static String buildUpperLikeSql(@Nullable String textQuery) { | |||
if (isBlank(textQuery)) { | |||
return null; | |||
} | |||
return buildLikeValue(textQuery.toUpperCase(Locale.ENGLISH), BEFORE_AND_AFTER); | |||
} | |||
private static ComponentMapper mapper(DbSession session) { | |||
return session.getMapper(ComponentMapper.class); | |||
} |
@@ -20,7 +20,6 @@ | |||
package org.sonar.db.component; | |||
import com.google.common.annotations.VisibleForTesting; | |||
import com.google.common.collect.ImmutableSet; | |||
import com.google.common.collect.Lists; | |||
import java.util.Collection; | |||
import java.util.HashMap; | |||
@@ -36,10 +35,10 @@ import java.util.stream.Collectors; | |||
import javax.annotation.Nullable; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.resources.Qualifiers; | |||
import org.sonar.api.resources.Scopes; | |||
import org.sonar.db.Dao; | |||
import org.sonar.db.DbSession; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static org.sonar.core.component.ComponentKeys.checkProjectKey; | |||
/** | |||
@@ -48,25 +47,21 @@ import static org.sonar.core.component.ComponentKeys.checkProjectKey; | |||
* @since 3.2 | |||
*/ | |||
public class ComponentKeyUpdaterDao implements Dao { | |||
private static final Set<String> PROJECT_OR_MODULE_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.MODULE); | |||
public void updateKey(DbSession dbSession, String projectOrModuleUuid, String newKey) { | |||
public void updateKey(DbSession dbSession, String projectUuid, String newKey) { | |||
ComponentKeyUpdaterMapper mapper = dbSession.getMapper(ComponentKeyUpdaterMapper.class); | |||
if (mapper.countResourceByKey(newKey) > 0) { | |||
throw new IllegalArgumentException("Impossible to update key: a component with key \"" + newKey + "\" already exists."); | |||
} | |||
// must SELECT first everything | |||
ResourceDto project = mapper.selectProjectByUuid(projectOrModuleUuid); | |||
ResourceDto project = mapper.selectProjectByUuid(projectUuid); | |||
String projectOldKey = project.getKey(); | |||
List<ResourceDto> resources = mapper.selectProjectResources(projectOrModuleUuid); | |||
List<ResourceDto> resources = mapper.selectProjectResources(projectUuid); | |||
resources.add(project); | |||
// add branch components | |||
dbSession.getMapper(BranchMapper.class).selectByProjectUuid(projectOrModuleUuid) | |||
.stream() | |||
.filter(branch -> !projectOrModuleUuid.equals(branch.getUuid())) | |||
dbSession.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid).stream() | |||
.filter(branch -> !projectUuid.equals(branch.getUuid())) | |||
.forEach(branch -> { | |||
resources.addAll(mapper.selectProjectResources(branch.getUuid())); | |||
resources.add(mapper.selectProjectByUuid(branch.getUuid())); | |||
@@ -77,10 +72,6 @@ public class ComponentKeyUpdaterDao implements Dao { | |||
}); | |||
} | |||
public static void checkIsProjectOrModule(ComponentDto component) { | |||
checkArgument(PROJECT_OR_MODULE_QUALIFIERS.contains(component.qualifier()), "Component updated must be a module or a key"); | |||
} | |||
/** | |||
* | |||
* @return a map with currentKey/newKey is a bulk update was executed | |||
@@ -118,8 +109,7 @@ public class ComponentKeyUpdaterDao implements Dao { | |||
// add branches (no check should be done as branch keys cannot be changed by the user) | |||
Map<String, String> branchBaseKeys = new HashMap<>(); | |||
session.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid) | |||
.stream() | |||
session.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid).stream() | |||
.filter(branch -> !projectUuid.equals(branch.getUuid())) | |||
.forEach(branch -> { | |||
Set<ResourceDto> branchModules = collectAllModules(branch.getUuid(), stringToReplace, mapper, true); | |||
@@ -167,14 +157,18 @@ public class ComponentKeyUpdaterDao implements Dao { | |||
@Nullable BiConsumer<ResourceDto, String> consumer) { | |||
for (ResourceDto resource : resources) { | |||
String oldResourceKey = resource.getKey(); | |||
String newResourceKey = newKey + oldResourceKey.substring(oldKey.length(), oldResourceKey.length()); | |||
String newResourceKey = newKey + oldResourceKey.substring(oldKey.length()); | |||
resource.setKey(newResourceKey); | |||
String oldResourceDeprecatedKey = resource.getDeprecatedKey(); | |||
if (StringUtils.isNotBlank(oldResourceDeprecatedKey)) { | |||
String newResourceDeprecatedKey = newKey + oldResourceDeprecatedKey.substring(oldKey.length(), oldResourceDeprecatedKey.length()); | |||
String newResourceDeprecatedKey = newKey + oldResourceDeprecatedKey.substring(oldKey.length()); | |||
resource.setDeprecatedKey(newResourceDeprecatedKey); | |||
} | |||
mapper.update(resource); | |||
mapper.updateComponent(resource); | |||
if (resource.getScope().equals(Scopes.PROJECT) && (resource.getQualifier().equals(Qualifiers.PROJECT) || resource.getQualifier().equals(Qualifiers.APP))) { | |||
mapper.updateProject(oldResourceKey, newResourceKey); | |||
} | |||
if (consumer != null) { | |||
consumer.accept(resource, oldResourceKey); | |||
} |
@@ -32,6 +32,8 @@ public interface ComponentKeyUpdaterMapper { | |||
List<ResourceDto> selectDescendantProjects(@Param("rootUuid") String rootUuid); | |||
void update(ResourceDto resource); | |||
void updateComponent(ResourceDto resource); | |||
void updateProject(@Param("oldProjectKey") String oldProjectKey, @Param("newProjectKey") String newProjectKey); | |||
} |
@@ -29,6 +29,7 @@ import org.sonar.api.utils.DateUtils; | |||
import org.sonar.core.util.UuidFactoryFast; | |||
import org.sonar.core.util.Uuids; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.db.rule.RuleDto; | |||
@@ -47,13 +48,22 @@ public class IssueTesting { | |||
public static IssueDto newIssue(RuleDefinitionDto rule, ComponentDto project, ComponentDto file) { | |||
checkArgument(project.qualifier().equals(Qualifiers.PROJECT), "Second parameter should be a project"); | |||
checkArgument(file.projectUuid().equals(project.uuid()), "The file doesn't belong to the project"); | |||
return newIssue(rule, project.uuid(), project.getDbKey(), file); | |||
} | |||
public static IssueDto newIssue(RuleDefinitionDto rule, ProjectDto project, ComponentDto file) { | |||
return newIssue(rule, project.getUuid(), project.getKey(), file); | |||
} | |||
public static IssueDto newIssue(RuleDefinitionDto rule, String projectUuid, String projectKey, ComponentDto file) { | |||
checkArgument(file.projectUuid().equals(projectUuid), "The file doesn't belong to the project"); | |||
return new IssueDto() | |||
.setKee("uuid_" + randomAlphabetic(5)) | |||
.setRule(rule) | |||
.setType(RuleType.values()[nextInt(RuleType.values().length)]) | |||
.setProject(project) | |||
.setProjectUuid(projectUuid) | |||
.setProjectKey(projectKey) | |||
.setComponent(file) | |||
.setStatus(Issue.STATUS_OPEN) | |||
.setResolution(null) |
@@ -69,10 +69,11 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea | |||
CoreMetrics.NEW_LINES_KEY, | |||
CoreMetrics.NEW_RELIABILITY_RATING_KEY); | |||
// TODO filter on enabled projects | |||
private static final String SQL_PROJECTS = "SELECT p.organization_uuid, p.uuid, p.kee, p.name, s.created_at, p.tags " + | |||
"FROM projects p " + | |||
"LEFT OUTER JOIN snapshots s ON s.component_uuid=p.uuid AND s.islast=? " + | |||
"WHERE p.enabled=? AND p.scope=? AND p.qualifier=? and p.main_branch_project_uuid is null "; | |||
"WHERE p.qualifier=?"; | |||
private static final String PROJECT_FILTER = " AND p.uuid=?"; | |||
@@ -130,11 +131,9 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea | |||
} | |||
PreparedStatement stmt = session.getConnection().prepareStatement(sql.toString()); | |||
stmt.setBoolean(1, true); | |||
stmt.setBoolean(2, true); | |||
stmt.setString(3, Scopes.PROJECT); | |||
stmt.setString(4, Qualifiers.PROJECT); | |||
stmt.setString(2, Qualifiers.PROJECT); | |||
if (projectUuid != null) { | |||
stmt.setString(5, projectUuid); | |||
stmt.setString(3, projectUuid); | |||
} | |||
return stmt; | |||
} catch (SQLException e) { |
@@ -0,0 +1,88 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.project; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import java.util.Set; | |||
import org.sonar.db.Dao; | |||
import org.sonar.db.DbSession; | |||
public class ProjectDao implements Dao { | |||
public void insert(DbSession session, ProjectDto item) { | |||
mapper(session).insert(item); | |||
} | |||
public Optional<ProjectDto> selectProjectByKey(DbSession session, String key) { | |||
return Optional.ofNullable(mapper(session).selectProjectByKey(key)); | |||
} | |||
public Optional<ProjectDto> selectApplicationByKey(DbSession session, String key) { | |||
return Optional.ofNullable(mapper(session).selectApplicationByKey(key)); | |||
} | |||
public Optional<ProjectDto> selectProjectOrAppByKey(DbSession session, String key) { | |||
return Optional.ofNullable(mapper(session).selectProjectOrAppByKey(key)); | |||
} | |||
public List<ProjectDto> selectProjectsByKeys(DbSession session, Set<String> keys) { | |||
if (keys.isEmpty()) { | |||
return Collections.emptyList(); | |||
} | |||
return mapper(session).selectProjectsByKeys(keys); | |||
} | |||
public List<ProjectDto> selectProjects(DbSession session) { | |||
return mapper(session).selectProjects(); | |||
} | |||
public Optional<ProjectDto> selectByUuid(DbSession session, String uuid) { | |||
return Optional.ofNullable(mapper(session).selectByUuid(uuid)); | |||
} | |||
public List<ProjectDto> selectByOrganizationUuid(DbSession session, String organizationUuid) { | |||
return mapper(session).selectByOrganizationUuid(organizationUuid); | |||
} | |||
public List<ProjectDto> selectProjectsByOrganizationUuid(DbSession session, String organizationUuid) { | |||
return mapper(session).selectProjectsByOrganizationUuid(organizationUuid); | |||
} | |||
public List<ProjectDto> selectByUuids(DbSession session, Set<String> uuids) { | |||
if (uuids.isEmpty()) { | |||
return Collections.emptyList(); | |||
} | |||
return mapper(session).selectByUuids(uuids); | |||
} | |||
public void updateTags(DbSession session, ProjectDto project) { | |||
mapper(session).updateTags(project); | |||
} | |||
public void update(DbSession session, ProjectDto project) { | |||
mapper(session).update(project); | |||
} | |||
private static ProjectMapper mapper(DbSession session) { | |||
return session.getMapper(ProjectMapper.class); | |||
} | |||
} |
@@ -0,0 +1,184 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.project; | |||
import java.util.List; | |||
import java.util.Objects; | |||
import java.util.stream.Collectors; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import static org.apache.commons.lang.StringUtils.trimToNull; | |||
import static org.sonar.db.component.DbTagsReader.readDbTags; | |||
public class ProjectDto { | |||
private static final String TAGS_SEPARATOR = ","; | |||
private String uuid; | |||
private String kee; | |||
private String qualifier; | |||
private String name; | |||
private String description; | |||
private boolean isPrivate = false; | |||
private String tags; | |||
private long createdAt; | |||
private long updatedAt; | |||
private String organizationUuid; | |||
public ProjectDto() { | |||
// nothing to do here | |||
} | |||
public long getCreatedAt() { | |||
return createdAt; | |||
} | |||
public ProjectDto setCreatedAt(long createdAt) { | |||
this.createdAt = createdAt; | |||
return this; | |||
} | |||
public long getUpdatedAt() { | |||
return updatedAt; | |||
} | |||
public ProjectDto setUpdatedAt(long updatedAt) { | |||
this.updatedAt = updatedAt; | |||
return this; | |||
} | |||
public String getUuid() { | |||
return uuid; | |||
} | |||
public ProjectDto setUuid(String uuid) { | |||
this.uuid = uuid; | |||
return this; | |||
} | |||
/** | |||
* This is the getter used by MyBatis mapper. | |||
*/ | |||
public String getKee() { | |||
return kee; | |||
} | |||
public String getKey() { | |||
return getKee(); | |||
} | |||
/** | |||
* This is the setter used by MyBatis mapper. | |||
*/ | |||
public ProjectDto setKee(String kee) { | |||
this.kee = kee; | |||
return this; | |||
} | |||
public ProjectDto setKey(String key) { | |||
return setKee(key); | |||
} | |||
public boolean isPrivate() { | |||
return isPrivate; | |||
} | |||
public ProjectDto setPrivate(boolean aPrivate) { | |||
isPrivate = aPrivate; | |||
return this; | |||
} | |||
public List<String> getTags() { | |||
return readDbTags(tags); | |||
} | |||
public ProjectDto setTags(List<String> tags) { | |||
setTagsString(tags.stream() | |||
.filter(t -> !t.isEmpty()) | |||
.collect(Collectors.joining(TAGS_SEPARATOR))); | |||
return this; | |||
} | |||
/** | |||
* Used by MyBatis | |||
*/ | |||
@CheckForNull | |||
public String getTagsString() { | |||
return tags; | |||
} | |||
public ProjectDto setTagsString(@Nullable String tags) { | |||
this.tags = trimToNull(tags); | |||
return this; | |||
} | |||
public String getOrganizationUuid() { | |||
return organizationUuid; | |||
} | |||
public ProjectDto setOrganizationUuid(String organizationUuid) { | |||
this.organizationUuid = organizationUuid; | |||
return this; | |||
} | |||
public String getName() { | |||
return name; | |||
} | |||
public ProjectDto setName(String name) { | |||
this.name = name; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getDescription() { | |||
return description; | |||
} | |||
public ProjectDto setDescription(@Nullable String description) { | |||
this.description = description; | |||
return this; | |||
} | |||
public String getQualifier() { | |||
return qualifier; | |||
} | |||
public ProjectDto setQualifier(String qualifier) { | |||
this.qualifier = qualifier; | |||
return this; | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
if (this == o) { | |||
return true; | |||
} | |||
if (o == null || getClass() != o.getClass()) { | |||
return false; | |||
} | |||
ProjectDto that = (ProjectDto) o; | |||
return Objects.equals(uuid, that.uuid); | |||
} | |||
@Override | |||
public int hashCode() { | |||
return uuid != null ? uuid.hashCode() : 0; | |||
} | |||
} |
@@ -0,0 +1,56 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.project; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import javax.annotation.CheckForNull; | |||
import org.apache.ibatis.annotations.Param; | |||
public interface ProjectMapper { | |||
void insert(ProjectDto project); | |||
@CheckForNull | |||
ProjectDto selectProjectByKey(String key); | |||
@CheckForNull | |||
ProjectDto selectApplicationByKey(String key); | |||
@CheckForNull | |||
ProjectDto selectProjectOrAppByKey(String key); | |||
List<ProjectDto> selectProjectsByKeys(@Param("kees") Collection<String> kees); | |||
@CheckForNull | |||
ProjectDto selectByUuid(String uuid); | |||
List<ProjectDto> selectByUuids(@Param("uuids") Collection<String> uuids); | |||
List<ProjectDto> selectByOrganizationUuid(String organizationUuid); | |||
void updateTags(ProjectDto project); | |||
void update(ProjectDto project); | |||
List<ProjectDto> selectProjects(); | |||
List<ProjectDto> selectProjectsByOrganizationUuid(String organizationUuid); | |||
} |
@@ -0,0 +1,201 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.project; | |||
import java.util.Date; | |||
import java.util.Locale; | |||
import java.util.Set; | |||
import java.util.stream.Stream; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import org.sonar.db.WildcardPosition; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static org.sonar.db.DaoUtils.buildLikeValue; | |||
public class ProjectQuery { | |||
private final String nameOrKeyQuery; | |||
private final boolean partialMatchOnKey; | |||
private final Boolean isPrivate; | |||
private final Set<String> projectUuids; | |||
private final Set<String> projectKeys; | |||
private final Long analyzedBefore; | |||
private final Long anyBranchAnalyzedBefore; | |||
private final Long anyBranchAnalyzedAfter; | |||
private final Date createdAfter; | |||
private final boolean onProvisionedOnly; | |||
private ProjectQuery(ProjectQuery.Builder builder) { | |||
this.nameOrKeyQuery = builder.nameOrKeyQuery; | |||
this.partialMatchOnKey = builder.partialMatchOnKey != null && builder.partialMatchOnKey; | |||
this.projectUuids = builder.projectUuids; | |||
this.projectKeys = builder.projectKeys; | |||
this.isPrivate = builder.isPrivate; | |||
this.analyzedBefore = builder.analyzedBefore; | |||
this.anyBranchAnalyzedBefore = builder.anyBranchAnalyzedBefore; | |||
this.anyBranchAnalyzedAfter = builder.anyBranchAnalyzedAfter; | |||
this.createdAfter = builder.createdAfter; | |||
this.onProvisionedOnly = builder.onProvisionedOnly; | |||
} | |||
@CheckForNull | |||
public String getNameOrKeyQuery() { | |||
return nameOrKeyQuery; | |||
} | |||
/** | |||
* Used by MyBatis mapper | |||
*/ | |||
@CheckForNull | |||
public String getNameOrKeyUpperLikeQuery() { | |||
return buildLikeValue(nameOrKeyQuery, WildcardPosition.BEFORE_AND_AFTER).toUpperCase(Locale.ENGLISH); | |||
} | |||
/** | |||
* Used by MyBatis mapper | |||
*/ | |||
public boolean isPartialMatchOnKey() { | |||
return partialMatchOnKey; | |||
} | |||
@CheckForNull | |||
public Set<String> getProjectUuids() { | |||
return projectUuids; | |||
} | |||
@CheckForNull | |||
public Set<String> getProjectKeys() { | |||
return projectKeys; | |||
} | |||
@CheckForNull | |||
public Boolean getPrivate() { | |||
return isPrivate; | |||
} | |||
@CheckForNull | |||
public Long getAnalyzedBefore() { | |||
return analyzedBefore; | |||
} | |||
@CheckForNull | |||
public Long getAnyBranchAnalyzedBefore() { | |||
return anyBranchAnalyzedBefore; | |||
} | |||
@CheckForNull | |||
public Long getAnyBranchAnalyzedAfter() { | |||
return anyBranchAnalyzedAfter; | |||
} | |||
@CheckForNull | |||
public Date getCreatedAfter() { | |||
return createdAfter; | |||
} | |||
public boolean isOnProvisionedOnly() { | |||
return onProvisionedOnly; | |||
} | |||
boolean hasEmptySetOfProjects() { | |||
return Stream.of(projectKeys, projectUuids) | |||
.anyMatch(list -> list != null && list.isEmpty()); | |||
} | |||
public static ProjectQuery.Builder builder() { | |||
return new ProjectQuery.Builder(); | |||
} | |||
public static class Builder { | |||
private String nameOrKeyQuery; | |||
private Boolean partialMatchOnKey; | |||
private Boolean isPrivate; | |||
private Set<String> projectUuids; | |||
private Set<String> projectKeys; | |||
private Long analyzedBefore; | |||
private Long anyBranchAnalyzedBefore; | |||
private Long anyBranchAnalyzedAfter; | |||
private Date createdAfter; | |||
private boolean onProvisionedOnly = false; | |||
public ProjectQuery.Builder setNameOrKeyQuery(@Nullable String nameOrKeyQuery) { | |||
this.nameOrKeyQuery = nameOrKeyQuery; | |||
return this; | |||
} | |||
/** | |||
* Beware, can be resource intensive! Should be used with precautions. | |||
*/ | |||
public ProjectQuery.Builder setPartialMatchOnKey(@Nullable Boolean partialMatchOnKey) { | |||
this.partialMatchOnKey = partialMatchOnKey; | |||
return this; | |||
} | |||
public ProjectQuery.Builder setProjectUuids(@Nullable Set<String> projectUuids) { | |||
this.projectUuids = projectUuids; | |||
return this; | |||
} | |||
public ProjectQuery.Builder setProjectKeys(@Nullable Set<String> projectKeys) { | |||
this.projectKeys = projectKeys; | |||
return this; | |||
} | |||
public ProjectQuery.Builder setPrivate(@Nullable Boolean isPrivate) { | |||
this.isPrivate = isPrivate; | |||
return this; | |||
} | |||
public ProjectQuery.Builder setAnalyzedBefore(@Nullable Long l) { | |||
this.analyzedBefore = l; | |||
return this; | |||
} | |||
public ProjectQuery.Builder setAnyBranchAnalyzedBefore(@Nullable Long l) { | |||
this.anyBranchAnalyzedBefore = l; | |||
return this; | |||
} | |||
/** | |||
* Filter on date of last analysis. On projects, all branches and pull requests are taken into | |||
* account. For example the analysis of a branch is included in the filter | |||
* even if the main branch has never been analyzed. | |||
*/ | |||
public ProjectQuery.Builder setAnyBranchAnalyzedAfter(@Nullable Long l) { | |||
this.anyBranchAnalyzedAfter = l; | |||
return this; | |||
} | |||
public ProjectQuery.Builder setCreatedAfter(@Nullable Date l) { | |||
this.createdAfter = l; | |||
return this; | |||
} | |||
public ProjectQuery.Builder setOnProvisionedOnly(boolean onProvisionedOnly) { | |||
this.onProvisionedOnly = onProvisionedOnly; | |||
return this; | |||
} | |||
public ProjectQuery build() { | |||
checkArgument(nameOrKeyQuery != null || partialMatchOnKey == null, "A query must be provided if a partial match on key is specified."); | |||
return new ProjectQuery(this); | |||
} | |||
} | |||
} |
@@ -0,0 +1,24 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.db.project; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -109,7 +109,7 @@ public class PropertiesDao implements Dao { | |||
private static PreparedStatement createStatement(String projectUuid, Collection<String> dispatcherKeys, Connection connection) throws SQLException { | |||
String sql = "SELECT count(1) FROM properties pp " + | |||
"left outer join projects pj on pp.resource_id = pj.id " + | |||
"left outer join components pj on pp.resource_id = pj.id " + | |||
"where pp.user_id is not null and (pp.resource_id is null or pj.uuid=?) " + | |||
"and (" + repeat("pp.prop_key like ?", " or ", dispatcherKeys.size()) + ")"; | |||
PreparedStatement res = connection.prepareStatement(sql); |
@@ -283,6 +283,13 @@ class PurgeCommands { | |||
profiler.stop(); | |||
} | |||
void deleteProject(String projectUuid) { | |||
profiler.start("deleteProject (projects)"); | |||
purgeMapper.deleteProjectsByProjectUuid(projectUuid); | |||
session.commit(); | |||
profiler.stop(); | |||
} | |||
void deleteComponents(List<String> componentUuids) { | |||
if (componentUuids.isEmpty()) { | |||
return; |
@@ -211,8 +211,7 @@ public class PurgeDao implements Dao { | |||
PurgeMapper purgeMapper = mapper(session); | |||
PurgeCommands purgeCommands = new PurgeCommands(session, profiler, system2); | |||
session.getMapper(BranchMapper.class).selectByProjectUuid(uuid) | |||
.stream() | |||
session.getMapper(BranchMapper.class).selectByProjectUuid(uuid).stream() | |||
.filter(branch -> !uuid.equals(branch.getUuid())) | |||
.forEach(branch -> deleteRootComponent(branch.getUuid(), purgeMapper, purgeCommands)); | |||
@@ -242,6 +241,7 @@ public class PurgeDao implements Dao { | |||
commands.deleteNewCodePeriods(rootUuid); | |||
commands.deleteBranch(rootUuid); | |||
commands.deleteComponents(rootUuid); | |||
commands.deleteProject(rootUuid); | |||
} | |||
/** |
@@ -74,6 +74,8 @@ public interface PurgeMapper { | |||
void deleteComponentsByProjectUuid(@Param("rootUuid") String rootUuid); | |||
void deleteProjectsByProjectUuid(@Param("projectUuid") String projectUuid); | |||
void deleteComponentsByUuids(@Param("componentUuids") List<String> componentUuids); | |||
void deleteGroupRolesByComponentId(@Param("rootId") long rootId); |
@@ -31,11 +31,11 @@ public class ProjectQgateAssociationDao implements Dao { | |||
} | |||
/** | |||
* @return quality gate uuid if a specific Quality Gate has been defined for the given component uuid. <br> | |||
* @return quality gate uuid if a specific Quality Gate has been defined for the given project uuid. <br> | |||
* Returns <code>{@link Optional#empty()}</code> otherwise (ex: default quality gate applies) | |||
*/ | |||
public Optional<String> selectQGateUuidByComponentUuid(DbSession dbSession, String componentUuid) { | |||
String uuid = mapper(dbSession).selectQGateUuidByComponentUuid(componentUuid); | |||
public Optional<String> selectQGateUuidByProjectUuid(DbSession dbSession, String projectUuid) { | |||
String uuid = mapper(dbSession).selectQGateUuidByProjectUuid(projectUuid); | |||
return Optional.ofNullable(uuid); | |||
} | |||
@@ -28,7 +28,7 @@ public interface ProjectQgateAssociationMapper { | |||
List<ProjectQgateAssociationDto> selectProjects(@Param("query") ProjectQgateAssociationQuery query); | |||
@CheckForNull | |||
String selectQGateUuidByComponentUuid(String componentUuid); | |||
String selectQGateUuidByProjectUuid(String projectUuid); | |||
void deleteByProjectUuid(String projectUuid); | |||
@@ -107,7 +107,7 @@ public class QualityGateDao implements Dao { | |||
return session.getMapper(QualityGateMapper.class); | |||
} | |||
public QualityGateDto selectByProjectUuid(DbSession dbSession, String uuid) { | |||
return mapper(dbSession).selectByProjectUuid(uuid); | |||
public QualityGateDto selectByProjectUuid(DbSession dbSession, String projectUuid) { | |||
return mapper(dbSession).selectByProjectUuid(projectUuid); | |||
} | |||
} |
@@ -35,8 +35,8 @@ import org.sonar.db.DatabaseUtils; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.KeyLongValue; | |||
import org.sonar.db.RowNotFoundException; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static java.util.Collections.emptyList; | |||
@@ -156,12 +156,12 @@ public class QualityProfileDao implements Dao { | |||
} | |||
@CheckForNull | |||
public QProfileDto selectAssociatedToProjectAndLanguage(DbSession dbSession, ComponentDto project, String language) { | |||
return mapper(dbSession).selectAssociatedToProjectUuidAndLanguage(project.getOrganizationUuid(), project.projectUuid(), language); | |||
public QProfileDto selectAssociatedToProjectAndLanguage(DbSession dbSession, ProjectDto project, String language) { | |||
return mapper(dbSession).selectAssociatedToProjectUuidAndLanguage(project.getOrganizationUuid(), project.getUuid(), language); | |||
} | |||
public List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession dbSession, ComponentDto project, Collection<String> languages) { | |||
return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.uuid(), partition)); | |||
public List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession dbSession, ProjectDto project, Collection<String> languages) { | |||
return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.getUuid(), partition)); | |||
} | |||
public List<QProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) { | |||
@@ -205,16 +205,16 @@ public class QualityProfileDao implements Dao { | |||
return KeyLongValue.toMap(executeLargeInputs(profileUuids, partition -> mapper(dbSession).countProjectsByOrganizationAndProfiles(organization.getUuid(), partition))); | |||
} | |||
public void insertProjectProfileAssociation(DbSession dbSession, ComponentDto project, QProfileDto profile) { | |||
mapper(dbSession).insertProjectProfileAssociation(project.uuid(), profile.getKee()); | |||
public void insertProjectProfileAssociation(DbSession dbSession, ProjectDto project, QProfileDto profile) { | |||
mapper(dbSession).insertProjectProfileAssociation(project.getUuid(), profile.getKee()); | |||
} | |||
public void deleteProjectProfileAssociation(DbSession dbSession, ComponentDto project, QProfileDto profile) { | |||
mapper(dbSession).deleteProjectProfileAssociation(project.uuid(), profile.getKee()); | |||
public void deleteProjectProfileAssociation(DbSession dbSession, ProjectDto project, QProfileDto profile) { | |||
mapper(dbSession).deleteProjectProfileAssociation(project.getUuid(), profile.getKee()); | |||
} | |||
public void updateProjectProfileAssociation(DbSession dbSession, ComponentDto project, String newProfileUuid, String oldProfileUuid) { | |||
mapper(dbSession).updateProjectProfileAssociation(project.uuid(), newProfileUuid, oldProfileUuid); | |||
public void updateProjectProfileAssociation(DbSession dbSession, ProjectDto project, String newProfileUuid, String oldProfileUuid) { | |||
mapper(dbSession).updateProjectProfileAssociation(project.getUuid(), newProfileUuid, oldProfileUuid); | |||
} | |||
public void deleteProjectAssociationsByProfileUuids(DbSession dbSession, Collection<String> profileUuids) { |
@@ -36,6 +36,7 @@ import org.sonar.db.Dao; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static java.util.Locale.ENGLISH; | |||
import static org.sonar.db.DatabaseUtils.executeLargeInputs; | |||
@@ -143,6 +144,10 @@ public class UserDao implements Dao { | |||
mapper(dbSession).clearHomepages("ORGANIZATION", organization.getUuid(), system2.now()); | |||
} | |||
public void cleanHomepage(DbSession dbSession, ProjectDto project) { | |||
mapper(dbSession).clearHomepages("PROJECT", project.getUuid(), system2.now()); | |||
} | |||
public void cleanHomepage(DbSession dbSession, ComponentDto project) { | |||
mapper(dbSession).clearHomepages("PROJECT", project.uuid(), system2.now()); | |||
} |
@@ -26,6 +26,7 @@ import org.sonar.db.Dao; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static com.google.common.base.Preconditions.checkState; | |||
@@ -49,8 +50,8 @@ public class WebhookDao implements Dao { | |||
return mapper(dbSession).selectForOrganizationUuidOrderedByName(organizationUuid); | |||
} | |||
public List<WebhookDto> selectByProject(DbSession dbSession, ComponentDto componentDto) { | |||
return mapper(dbSession).selectForProjectUuidOrderedByName(componentDto.uuid()); | |||
public List<WebhookDto> selectByProject(DbSession dbSession, ProjectDto projectDto) { | |||
return mapper(dbSession).selectForProjectUuidOrderedByName(projectDto.getUuid()); | |||
} | |||
public void insert(DbSession dbSession, WebhookDto dto) { | |||
@@ -73,8 +74,8 @@ public class WebhookDao implements Dao { | |||
mapper(dbSession).deleteForOrganizationUuid(organization.getUuid()); | |||
} | |||
public void deleteByProject(DbSession dbSession, ComponentDto componentDto) { | |||
mapper(dbSession).deleteForProjectUuid(componentDto.uuid()); | |||
public void deleteByProject(DbSession dbSession, ProjectDto projectDto) { | |||
mapper(dbSession).deleteForProjectUuid(projectDto.getUuid()); | |||
} | |||
private static WebhookMapper mapper(DbSession dbSession) { |
@@ -95,7 +95,7 @@ | |||
p.kee as projectKey | |||
from | |||
project_alm_bindings b | |||
inner join projects p | |||
inner join components p | |||
on b.project_uuid = p.project_uuid | |||
where | |||
alm_id = #{almId, jdbcType=VARCHAR} |
@@ -76,6 +76,16 @@ | |||
pb.key_type = #{keyType, jdbcType=VARCHAR} | |||
</select> | |||
<select id="selectByBranchKeys" resultType="org.sonar.db.component.BranchDto"> | |||
select | |||
<include refid="columns" /> | |||
from project_branches pb | |||
where | |||
<foreach collection="branchKeyByProjectUuid" index="key" item="value" open="" separator=" or " close=""> | |||
(pb.project_uuid=#{key,jdbcType=VARCHAR} and pb.kee=#{value,jdbcType=VARCHAR}) | |||
</foreach> | |||
</select> | |||
<select id="selectByProjectUuid" parameterType="string" resultType="org.sonar.db.component.BranchDto"> | |||
select <include refid="columns" /> | |||
from project_branches pb |
@@ -15,35 +15,41 @@ | |||
<select id="countResourceByKey" parameterType="String" resultType="int"> | |||
SELECT count(1) | |||
FROM projects | |||
FROM components | |||
WHERE kee = #{key,jdbcType=VARCHAR} | |||
</select> | |||
<select id="selectProjectByUuid" parameterType="String" resultMap="resourceResultMap"> | |||
select * from projects | |||
select * from components | |||
where uuid = #{uuid,jdbcType=VARCHAR} | |||
</select> | |||
<select id="selectProjectResources" parameterType="String" resultMap="resourceResultMap"> | |||
select * from projects | |||
select * from components | |||
where | |||
root_uuid = #{rootUuid,jdbcType=VARCHAR} | |||
and scope != 'PRJ' | |||
</select> | |||
<select id="selectDescendantProjects" parameterType="String" resultMap="resourceResultMap"> | |||
select * from projects | |||
select * from components | |||
where | |||
scope='PRJ' | |||
and root_uuid = #{rootUuid,jdbcType=VARCHAR} | |||
and uuid != #{rootUuid,jdbcType=VARCHAR} | |||
</select> | |||
<update id="update" parameterType="Resource"> | |||
update projects | |||
<update id="updateComponent" parameterType="Resource"> | |||
update components | |||
set kee = #{key,jdbcType=VARCHAR}, deprecated_kee = #{deprecatedKey,jdbcType=VARCHAR} | |||
where id = #{id,jdbcType=BIGINT} | |||
</update> | |||
<update id="updateProject"> | |||
update projects | |||
set kee = #{newProjectKey,jdbcType=VARCHAR} | |||
where kee = #{oldProjectKey,jdbcType=VARCHAR} | |||
</update> | |||
</mapper> | |||
@@ -30,7 +30,7 @@ | |||
<select id="selectByKey" parameterType="String" resultType="Component"> | |||
SELECT | |||
<include refid="componentColumns"/> | |||
FROM projects p | |||
FROM components p | |||
where | |||
p.kee=#{key,jdbcType=VARCHAR} | |||
</select> | |||
@@ -38,7 +38,7 @@ | |||
<select id="selectBranchByKeyAndBranchKey" parameterType="String" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
inner join project_branches pb on pb.uuid = p.project_uuid | |||
where | |||
(p.kee=#{dbKey,jdbcType=VARCHAR} OR p.kee=#{key,jdbcType=VARCHAR}) | |||
@@ -49,7 +49,7 @@ | |||
<select id="selectPrByKeyAndBranchKey" parameterType="String" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
inner join project_branches pb on pb.uuid = p.project_uuid | |||
where | |||
(p.kee=#{dbKey,jdbcType=VARCHAR} OR p.kee=#{key,jdbcType=VARCHAR}) | |||
@@ -60,14 +60,14 @@ | |||
<select id="selectById" parameterType="long" resultType="Component"> | |||
SELECT | |||
<include refid="componentColumns"/> | |||
FROM projects p | |||
FROM components p | |||
where p.id = #{id,jdbcType=BIGINT} | |||
</select> | |||
<select id="selectByUuid" parameterType="String" resultType="Component"> | |||
SELECT | |||
<include refid="componentColumns"/> | |||
FROM projects p | |||
FROM components p | |||
where | |||
p.uuid=#{uuid,jdbcType=VARCHAR} | |||
</select> | |||
@@ -76,7 +76,7 @@ | |||
select | |||
<include refid="componentColumns"/> | |||
from | |||
projects p | |||
components p | |||
inner join | |||
project_alm_bindings pab on pab.project_uuid = p.uuid | |||
where | |||
@@ -86,8 +86,8 @@ | |||
<select id="selectByProjectUuid" parameterType="string" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects root | |||
inner join projects p on p.project_uuid=root.uuid and p.organization_uuid=root.organization_uuid | |||
from components root | |||
inner join components p on p.project_uuid=root.uuid and p.organization_uuid=root.organization_uuid | |||
where | |||
root.uuid=#{projectUuid,jdbcType=VARCHAR} | |||
</select> | |||
@@ -95,7 +95,7 @@ | |||
<select id="selectByKeys" parameterType="String" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
where | |||
p.enabled=${_true} | |||
and p.main_branch_project_uuid is null | |||
@@ -108,7 +108,7 @@ | |||
<select id="selectByDbKeys" parameterType="String" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
where | |||
p.enabled=${_true} | |||
and p.kee in | |||
@@ -120,7 +120,7 @@ | |||
<select id="selectByKeysAndBranch" parameterType="String" resultType="Component"> | |||
SELECT | |||
<include refid="componentColumns"/> | |||
FROM projects p | |||
FROM components p | |||
INNER JOIN project_branches pb on pb.uuid = p.project_uuid | |||
<where> | |||
p.enabled=${_true} | |||
@@ -135,7 +135,7 @@ | |||
<select id="selectByIds" parameterType="long" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
where | |||
p.enabled=${_true} | |||
and p.id in | |||
@@ -147,7 +147,7 @@ | |||
<select id="selectByUuids" parameterType="String" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
where | |||
p.uuid in | |||
<foreach collection="uuids" open="(" close=")" item="uuid" separator=","> | |||
@@ -157,7 +157,7 @@ | |||
<select id="selectExistingUuids" parameterType="String" resultType="String"> | |||
select p.uuid | |||
from projects p | |||
from components p | |||
where | |||
p.uuid in | |||
<foreach collection="uuids" open="(" close=")" item="uuid" separator=","> | |||
@@ -168,8 +168,8 @@ | |||
<select id="selectSubProjectsByComponentUuids" parameterType="String" resultType="Component"> | |||
SELECT | |||
<include refid="componentColumns"/> | |||
FROM projects p | |||
INNER JOIN projects child ON | |||
FROM components p | |||
INNER JOIN components child ON | |||
child.root_uuid=p.uuid | |||
and child.enabled=${_true} | |||
and child.organization_uuid=p.organization_uuid | |||
@@ -185,12 +185,12 @@ | |||
<select id="selectDescendantModules" parameterType="map" resultType="Component"> | |||
SELECT | |||
<include refid="componentColumns"/> | |||
FROM projects p | |||
FROM components p | |||
<include refid="modulesTreeQuery"/> | |||
</select> | |||
<sql id="modulesTreeQuery"> | |||
INNER JOIN projects module ON | |||
INNER JOIN components module ON | |||
module.project_uuid = p.project_uuid | |||
and module.organization_uuid = p.organization_uuid | |||
and module.uuid = #{moduleUuid} | |||
@@ -218,8 +218,8 @@ | |||
p.module_uuid as moduleUuid, | |||
fs.src_hash as srcHash, | |||
fs.revision | |||
FROM projects root | |||
INNER JOIN projects p on | |||
FROM components root | |||
INNER JOIN components p on | |||
p.project_uuid=root.uuid | |||
and p.organization_uuid=root.organization_uuid | |||
and p.enabled=${_true} | |||
@@ -237,7 +237,7 @@ | |||
p.module_uuid as moduleUuid, | |||
fs.src_hash as srcHash, | |||
fs.revision | |||
FROM projects p | |||
FROM components p | |||
INNER JOIN file_sources fs ON | |||
fs.file_uuid=p.uuid | |||
<include refid="modulesTreeQuery"/> | |||
@@ -246,7 +246,7 @@ | |||
<select id="selectProjects" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
where | |||
p.enabled=${_true} | |||
AND p.scope='PRJ' | |||
@@ -257,7 +257,7 @@ | |||
<select id="selectProjectsByOrganization" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
where | |||
p.enabled=${_true} | |||
and p.scope='PRJ' | |||
@@ -269,7 +269,7 @@ | |||
<select id="selectComponentsByQualifiers" resultType="Component"> | |||
SELECT | |||
<include refid="componentColumns"/> | |||
FROM projects p | |||
FROM components p | |||
where | |||
<foreach collection="qualifiers" open="(" close=")" item="qualifier" separator="OR "> | |||
p.qualifier=#{qualifier,jdbcType=VARCHAR} | |||
@@ -279,7 +279,7 @@ | |||
<select id="countEnabledModulesByProjectUuid" resultType="int"> | |||
select | |||
count(1) | |||
from projects p | |||
from components p | |||
where | |||
p.enabled=${_true} | |||
and p.project_uuid = #{projectUuid,jdbcType=VARCHAR} | |||
@@ -289,7 +289,7 @@ | |||
<select id="countComponentByOrganizationAndId" resultType="int"> | |||
select | |||
count(1) | |||
from projects p | |||
from components p | |||
where | |||
p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} | |||
and p.id = #{componentId,jdbcType=BIGINT} | |||
@@ -308,7 +308,7 @@ | |||
</select> | |||
<sql id="sqlSelectByQuery"> | |||
from projects p | |||
from components p | |||
<if test="query.analyzedBefore!=null"> | |||
inner join snapshots sa on sa.component_uuid=p.uuid | |||
and sa.status='P' and sa.islast=${_true} and sa.created_at < #{query.analyzedBefore,jdbcType=BIGINT} | |||
@@ -424,7 +424,7 @@ | |||
<select id="selectDescendants" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
<include refid="selectDescendantsJoins"/> | |||
<where> | |||
<include refid="selectDescendantsFilters"/> | |||
@@ -432,7 +432,7 @@ | |||
</select> | |||
<sql id="selectDescendantsJoins"> | |||
inner join projects base on base.project_uuid = p.project_uuid and base.uuid = #{baseUuid} | |||
inner join components base on base.project_uuid = p.project_uuid and base.uuid = #{baseUuid} | |||
<choose> | |||
<when test="query.getStrategy().name() == 'CHILDREN'"> | |||
and p.uuid_path = #{baseUuidPath,jdbcType=VARCHAR} | |||
@@ -467,7 +467,7 @@ | |||
</sql> | |||
<select id="selectUuidsForQualifiers" resultType="UuidWithProjectUuid"> | |||
SELECT p.uuid as "uuid", p.project_uuid as "projectUuid" FROM projects p | |||
SELECT p.uuid as "uuid", p.project_uuid as "projectUuid" FROM components p | |||
where | |||
<foreach collection="qualifiers" open="(" close=")" item="qualifier" separator="OR "> | |||
p.qualifier=#{qualifier,jdbcType=VARCHAR} | |||
@@ -477,8 +477,8 @@ | |||
<select id="selectViewKeysWithEnabledCopyOfProject" resultType="String"> | |||
select | |||
distinct p.kee | |||
from projects p | |||
inner join projects leaf on | |||
from components p | |||
inner join components leaf on | |||
leaf.qualifier = 'TRK' | |||
and leaf.scope = 'FIL' | |||
and leaf.enabled = ${_true} | |||
@@ -493,7 +493,7 @@ | |||
<select id="selectProjectsFromView" resultType="String"> | |||
select p.copy_component_uuid | |||
from projects p | |||
from components p | |||
where | |||
p.enabled = ${_true} | |||
and p.project_uuid = #{projectViewUuid,jdbcType=VARCHAR} | |||
@@ -505,8 +505,8 @@ | |||
<select id="selectComponentsFromProjectKeyAndScope" parameterType="map" resultType="Component"> | |||
SELECT | |||
<include refid="componentColumns"/> | |||
FROM projects p | |||
INNER JOIN projects root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} | |||
FROM components p | |||
INNER JOIN components root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} | |||
<where> | |||
<if test="excludeDisabled"> | |||
p.enabled = ${_true} | |||
@@ -521,24 +521,24 @@ | |||
SELECT | |||
p.uuid as uuid, p.module_uuid as moduleUuid, p.path as path, p.scope as scope | |||
FROM | |||
projects p | |||
components p | |||
INNER JOIN | |||
projects root ON root.uuid=p.project_uuid AND p.enabled = ${_true} AND root.kee=#{projectKey,jdbcType=VARCHAR} | |||
components root ON root.uuid=p.project_uuid AND p.enabled = ${_true} AND root.kee=#{projectKey,jdbcType=VARCHAR} | |||
</select> | |||
<select id="selectUuidsByKeyFromProjectKey" parameterType="string" resultType="KeyWithUuid"> | |||
SELECT | |||
p.kee, p.uuid | |||
FROM | |||
projects p | |||
components p | |||
INNER JOIN | |||
projects root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} | |||
components root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} | |||
</select> | |||
<select id="scrollForIndexing" parameterType="map" resultType="Component" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY"> | |||
select | |||
<include refid="componentColumns"/> | |||
from projects p | |||
from components p | |||
where | |||
p.enabled=${_true} | |||
and p.copy_component_uuid is null | |||
@@ -555,7 +555,7 @@ | |||
p.kee as kee, | |||
p.path as path, | |||
fs.line_count as lineCount | |||
from projects p | |||
from components p | |||
inner join file_sources fs on | |||
fs.file_uuid = p.uuid | |||
where | |||
@@ -567,7 +567,7 @@ | |||
</select> | |||
<insert id="insert" parameterType="Component" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> | |||
INSERT INTO projects ( | |||
INSERT INTO components ( | |||
organization_uuid, | |||
kee, | |||
uuid, | |||
@@ -640,14 +640,14 @@ | |||
</insert> | |||
<update id="updateTags" parameterType="Component" useGeneratedKeys="false"> | |||
update projects set | |||
update components set | |||
tags = #{tagsString,jdbcType=VARCHAR} | |||
where | |||
uuid = #{uuid,jdbcType=VARCHAR} | |||
</update> | |||
<update id="update" parameterType="org.sonar.db.component.ComponentUpdateDto" useGeneratedKeys="false"> | |||
update projects set | |||
update components set | |||
b_changed = #{bChanged,jdbcType=BOOLEAN}, | |||
<!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules --> | |||
deprecated_kee = #{bKey,jdbcType=VARCHAR}, | |||
@@ -667,7 +667,7 @@ | |||
</update> | |||
<update id="updateBEnabledToFalse" parameterType="org.sonar.db.component.ComponentUpdateDto" useGeneratedKeys="false"> | |||
update projects set | |||
update components set | |||
b_changed = ${_true}, | |||
<!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules --> | |||
deprecated_kee = kee, | |||
@@ -687,7 +687,7 @@ | |||
</update> | |||
<update id="applyBChangesForRootComponentUuid" parameterType="string" useGeneratedKeys="false"> | |||
update projects set | |||
update components set | |||
<!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules --> | |||
kee = deprecated_kee, | |||
copy_component_uuid = b_copy_component_uuid, | |||
@@ -733,7 +733,7 @@ | |||
</update> | |||
<update id="resetBChangedForRootComponentUuid" parameterType="map" > | |||
update projects | |||
update components | |||
set b_changed = ${_false}, | |||
<!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules --> | |||
deprecated_kee = kee | |||
@@ -743,7 +743,7 @@ | |||
</update> | |||
<update id="setPrivateForRootComponentUuid" parameterType="map" > | |||
update projects set | |||
update components set | |||
private = #{isPrivate,jdbcType=BOOLEAN} | |||
where | |||
project_uuid = #{projectUuid,jdbcType=VARCHAR} | |||
@@ -751,11 +751,11 @@ | |||
</update> | |||
<delete id="delete" parameterType="long"> | |||
DELETE FROM projects WHERE id=#{id,jdbcType=BIGINT} | |||
DELETE FROM components WHERE id=#{id,jdbcType=BIGINT} | |||
</delete> | |||
<select id="selectAllSiblingComponentKeysHavingOpenIssues" resultType="KeyWithUuid"> | |||
SELECT DISTINCT p.kee as kee, p.uuid as uuid FROM projects p | |||
SELECT DISTINCT p.kee as kee, p.uuid as uuid FROM components p | |||
JOIN issues i | |||
ON p.uuid = i.component_uuid | |||
JOIN project_branches b | |||
@@ -771,7 +771,7 @@ | |||
from live_measures lm | |||
inner join metrics m on m.id = lm.metric_id | |||
inner join project_branches b on b.uuid = lm.component_uuid | |||
inner join projects p on b.project_uuid = p.uuid | |||
inner join components p on b.project_uuid = p.uuid | |||
where | |||
m.name = 'ncloc' | |||
and b.key_type = 'BRANCH' |
@@ -39,7 +39,7 @@ | |||
<select id="selectLastSnapshotByComponentUuid" resultType="Snapshot"> | |||
select <include refid="snapshotColumns" /> | |||
from snapshots s | |||
inner join projects p on s.component_uuid = p.project_uuid | |||
inner join components p on s.component_uuid = p.project_uuid | |||
where | |||
s.islast=${_true} | |||
and p.uuid = #{componentUuid,jdbcType=VARCHAR} | |||
@@ -67,7 +67,7 @@ | |||
<include refid="snapshotColumns" /> | |||
FROM snapshots s | |||
<if test="query.componentUuid != null"> | |||
INNER JOIN projects p ON p.uuid=s.component_uuid AND p.enabled=${_true} AND s.component_uuid=#{query.componentUuid,jdbcType=VARCHAR} | |||
INNER JOIN components p ON p.uuid=s.component_uuid AND p.enabled=${_true} AND s.component_uuid=#{query.componentUuid,jdbcType=VARCHAR} | |||
</if> | |||
<where> | |||
<if test="query.status != null"> | |||
@@ -104,7 +104,7 @@ | |||
select | |||
<include refid="snapshotColumns" /> | |||
from snapshots s | |||
inner join projects p on p.uuid=s.component_uuid and p.enabled=${_true} | |||
inner join components p on p.uuid=s.component_uuid and p.enabled=${_true} | |||
inner join project_branches pb on pb.uuid=p.uuid | |||
where | |||
<foreach collection="componentUuidFromDatePairs" open="(" close=")" item="componentUuidFromDatePair" separator=" or "> |
@@ -15,7 +15,7 @@ | |||
file_component.kee as componentKey | |||
FROM duplications_index duplication_block | |||
INNER JOIN snapshots snapshot ON duplication_block.analysis_uuid=snapshot.uuid AND snapshot.islast=${_true} | |||
INNER JOIN projects file_component ON file_component.uuid=duplication_block.component_uuid AND file_component.language=#{language} | |||
INNER JOIN components file_component ON file_component.uuid=duplication_block.component_uuid AND file_component.language=#{language} | |||
AND file_component.enabled=${_true} | |||
<where> | |||
AND duplication_block.hash in |
@@ -181,8 +181,8 @@ | |||
<include refid="issueColumns"/> | |||
from issues i | |||
inner join rules r on r.id=i.rule_id | |||
inner join projects p on p.uuid=i.component_uuid | |||
inner join projects root on root.uuid=i.project_uuid | |||
inner join components p on p.uuid=i.component_uuid | |||
inner join components root on root.uuid=i.project_uuid | |||
where i.kee=#{kee,jdbcType=VARCHAR} | |||
</select> | |||
@@ -191,8 +191,8 @@ | |||
<include refid="issueColumns"/> | |||
from issues i | |||
inner join rules r on r.id=i.rule_id | |||
inner join projects p on p.uuid=i.component_uuid | |||
inner join projects root on root.uuid=i.project_uuid | |||
inner join components p on p.uuid=i.component_uuid | |||
inner join components root on root.uuid=i.project_uuid | |||
where | |||
i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and | |||
i.status <> 'CLOSED' | |||
@@ -203,8 +203,8 @@ | |||
<include refid="issueColumns"/> | |||
from issues i | |||
inner join rules r on r.id=i.rule_id | |||
inner join projects p on p.uuid=i.component_uuid | |||
inner join projects root on root.uuid=i.project_uuid | |||
inner join components p on p.uuid=i.component_uuid | |||
inner join components root on root.uuid=i.project_uuid | |||
where | |||
(r.is_external is NULL or r.is_external = ${_false}) and | |||
i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and | |||
@@ -219,9 +219,9 @@ | |||
from issues i | |||
inner join rules r on | |||
r.id = i.rule_id | |||
inner join projects p on | |||
inner join components p on | |||
p.uuid = i.component_uuid | |||
inner join projects root on | |||
inner join components root on | |||
root.uuid = i.project_uuid | |||
inner join issue_changes ic on | |||
ic.issue_key = i.kee | |||
@@ -241,7 +241,7 @@ | |||
select | |||
distinct(i.component_uuid) | |||
from issues i | |||
inner join projects p on | |||
inner join components p on | |||
p.uuid = i.component_uuid | |||
and p.enabled = ${_true} | |||
where | |||
@@ -261,8 +261,8 @@ | |||
<include refid="issueColumns"/> | |||
from issues i | |||
inner join rules r on r.id=i.rule_id | |||
inner join projects p on p.uuid=i.component_uuid | |||
inner join projects root on root.uuid=i.project_uuid | |||
inner join components p on p.uuid=i.component_uuid | |||
inner join components root on root.uuid=i.project_uuid | |||
where i.kee in | |||
<foreach collection="list" open="(" close=")" item="key" separator=","> | |||
#{key,jdbcType=VARCHAR} | |||
@@ -274,8 +274,8 @@ | |||
<include refid="issueColumns"/> | |||
from issues i | |||
inner join rules r on r.id=i.rule_id | |||
inner join projects p on p.uuid=i.component_uuid | |||
inner join projects root on root.uuid=i.project_uuid | |||
inner join components p on p.uuid=i.component_uuid | |||
inner join components root on root.uuid=i.project_uuid | |||
where | |||
i.kee in | |||
<foreach collection="keys" open="(" close=")" item="key" separator=","> | |||
@@ -311,8 +311,8 @@ | |||
<include refid="issueColumns"/> | |||
from issues i | |||
inner join rules r on r.id = i.rule_id | |||
inner join projects p on p.uuid = i.component_uuid | |||
inner join projects root on root.uuid = i.project_uuid | |||
inner join components p on p.uuid = i.component_uuid | |||
inner join components root on root.uuid = i.project_uuid | |||
where | |||
(r.is_external is NULL or r.is_external = ${_false}) and | |||
i.project_uuid = #{projectUuid, jdbcType=VARCHAR} and | |||
@@ -324,7 +324,7 @@ | |||
<select id="selectIssueGroupsByBaseComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map"> | |||
select i.issue_type as ruleType, i.severity as severity, i.resolution as resolution, i.status as status, sum(i.effort) as effort, count(i.issue_type) as "count", (i.issue_creation_date >= #{leakPeriodBeginningDate,jdbcType=BIGINT}) as inLeak | |||
from issues i | |||
inner join projects p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid | |||
inner join components p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid | |||
where i.status !='CLOSED' | |||
and i.project_uuid = #{baseComponent.projectUuid,jdbcType=VARCHAR} | |||
and (p.uuid_path like #{baseComponent.uuidPathLikeIncludingSelf,jdbcType=VARCHAR} escape '/' or p.uuid = #{baseComponent.uuid,jdbcType=VARCHAR}) | |||
@@ -336,7 +336,7 @@ | |||
from ( | |||
select i.issue_type, i.severity, i.resolution, i.status, i.effort, case when i.issue_creation_date > #{leakPeriodBeginningDate,jdbcType=BIGINT} then 1 else 0 end as inLeak | |||
from issues i | |||
inner join projects p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid | |||
inner join components p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid | |||
where i.status !='CLOSED' | |||
and i.project_uuid = #{baseComponent.projectUuid,jdbcType=VARCHAR} | |||
and (p.uuid_path like #{baseComponent.uuidPathLikeIncludingSelf,jdbcType=VARCHAR} escape '/' or p.uuid = #{baseComponent.uuid,jdbcType=VARCHAR}) | |||
@@ -349,7 +349,7 @@ | |||
from ( | |||
select i.issue_type, i.severity, i.resolution, i.status, i.effort, case when i.issue_creation_date > #{leakPeriodBeginningDate,jdbcType=BIGINT} then 1 else 0 end as inLeak | |||
from issues i | |||
inner join projects p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid | |||
inner join components p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid | |||
where i.status !='CLOSED' | |||
and i.project_uuid = #{baseComponent.projectUuid,jdbcType=VARCHAR} | |||
and (p.uuid_path like #{baseComponent.uuidPathLikeIncludingSelf,jdbcType=VARCHAR} escape '/' or p.uuid = #{baseComponent.uuid,jdbcType=VARCHAR}) |
@@ -47,7 +47,7 @@ | |||
select b.project_uuid as projectUuid, max(lm.value) as maxncloc | |||
from live_measures lm | |||
inner join metrics m on m.id = lm.metric_id | |||
inner join projects p on p.uuid = lm.component_uuid | |||
inner join components p on p.uuid = lm.component_uuid | |||
inner join project_branches b on b.uuid = p.uuid | |||
<where> | |||
m.name = #{ncloc, jdbcType=VARCHAR} | |||
@@ -169,8 +169,8 @@ | |||
<select id="selectTreeByQuery" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY"> | |||
select <include refid="columns"/> from live_measures lm | |||
inner join projects p on p.uuid = lm.component_uuid | |||
<!-- TODO do we really need another join on projects ? Using lm.project_uuid should be enough --> | |||
inner join components p on p.uuid = lm.component_uuid | |||
<!-- TODO do we really need another join on components ? Using lm.project_uuid should be enough --> | |||
<include refid="org.sonar.db.component.ComponentMapper.selectDescendantsJoins"/> | |||
<where> | |||
<if test="query.getMetricIds() != null"> | |||
@@ -196,7 +196,7 @@ | |||
-- Add measures of base component | |||
union all | |||
select <include refid="columns"/> from live_measures lm | |||
inner join projects p on p.uuid = lm.component_uuid and lm.component_uuid = #{baseUuid, jdbcType=VARCHAR} | |||
inner join components p on p.uuid = lm.component_uuid and lm.component_uuid = #{baseUuid, jdbcType=VARCHAR} | |||
<where> | |||
<if test="query.getMetricIds() != null"> | |||
lm.metric_id in |
@@ -64,7 +64,7 @@ | |||
<select id="selectByQueryOnSingleComponent" parameterType="map" resultType="Measure"> | |||
select <include refid="measureColumns"/> from project_measures pm | |||
<include refid="selectByQueryCommonJoins"/> | |||
inner join projects p on p.project_uuid=analysis.component_uuid | |||
inner join components p on p.project_uuid=analysis.component_uuid | |||
and p.uuid=pm.component_uuid | |||
where | |||
<include refid="selectByQueryCommonFilters"/> |
@@ -124,7 +124,7 @@ | |||
and exists( | |||
select 1 | |||
from snapshots s | |||
inner join projects p on p.uuid = s.component_uuid | |||
inner join components p on p.uuid = s.component_uuid | |||
where p.organization_uuid = org.uuid | |||
and p.enabled = ${_true} | |||
and s.islast = ${_true} | |||
@@ -134,7 +134,7 @@ | |||
and exists( | |||
select 1 | |||
from snapshots s | |||
inner join projects p on p.uuid = s.component_uuid | |||
inner join components p on p.uuid = s.component_uuid | |||
where p.organization_uuid = org.uuid | |||
and p.enabled = ${_true} | |||
and s.islast = ${_true} | |||
@@ -192,7 +192,7 @@ | |||
select b.project_uuid, p.organization_uuid as orgUuid, max(lm.value) as maxncloc | |||
from live_measures lm | |||
inner join metrics m on m.id = lm.metric_id | |||
inner join projects p on p.uuid = lm.component_uuid | |||
inner join components p on p.uuid = lm.component_uuid | |||
inner join project_branches b on b.uuid = p.uuid | |||
where | |||
m.name = #{ncloc, jdbcType=VARCHAR} |
@@ -206,7 +206,7 @@ | |||
p.id | |||
from | |||
user_roles ur | |||
inner join projects p on | |||
inner join components p on | |||
p.id = ur.resource_id | |||
where | |||
ur.role=#{role, jdbcType=VARCHAR} | |||
@@ -241,7 +241,7 @@ | |||
select | |||
p.id | |||
from | |||
projects p | |||
components p | |||
where | |||
<foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or "> | |||
p.id=#{element ,jdbcType=BIGINT} | |||
@@ -252,7 +252,7 @@ | |||
<select id="keepAuthorizedProjectUuidsForUser" parameterType="map" resultType="String"> | |||
select p.uuid | |||
from projects p | |||
from components p | |||
inner join group_roles gr on p.id = gr.resource_id | |||
where | |||
gr.role = #{permission, jdbcType=VARCHAR} | |||
@@ -267,7 +267,7 @@ | |||
union | |||
select p.uuid | |||
from projects p | |||
from components p | |||
inner join user_roles ur on p.id = ur.resource_id | |||
where | |||
ur.role=#{permission, jdbcType=VARCHAR} | |||
@@ -278,7 +278,7 @@ | |||
union | |||
select p.uuid | |||
from projects p | |||
from components p | |||
where | |||
p.uuid in <foreach collection="projectUuids" open="(" close=")" item="projectUuid" index="index" separator=",">#{projectUuid, jdbcType=VARCHAR}</foreach> | |||
and p.private = ${_false} | |||
@@ -287,7 +287,7 @@ | |||
<select id="keepAuthorizedProjectUuidsForAnonymous" parameterType="map" resultType="String"> | |||
select p.uuid | |||
from projects p | |||
from components p | |||
inner join group_roles gr on p.id = gr.resource_id | |||
where | |||
gr.role=#{permission, jdbcType=VARCHAR} | |||
@@ -298,7 +298,7 @@ | |||
union | |||
select p.uuid | |||
from projects p | |||
from components p | |||
where | |||
p.uuid in <foreach collection="projectUuids" open="(" close=")" item="projectUuid" index="index" separator=",">#{projectUuid, jdbcType=VARCHAR}</foreach> | |||
and p.private = ${_false} | |||
@@ -349,7 +349,7 @@ | |||
select | |||
1 | |||
from | |||
projects p | |||
components p | |||
where | |||
p.id =#{componentId, jdbcType=BIGINT} | |||
and p.private = ${_false} | |||
@@ -360,7 +360,7 @@ | |||
<select id="selectProjectPermissions" parameterType="map" resultType="String"> | |||
select ur.role | |||
from user_roles ur | |||
inner join projects p on p.id = ur.resource_id | |||
inner join components p on p.id = ur.resource_id | |||
where | |||
p.uuid = #{projectUuid, jdbcType=VARCHAR} and | |||
p.organization_uuid = ur.organization_uuid and | |||
@@ -371,7 +371,7 @@ | |||
select gr.role | |||
from group_roles gr | |||
inner join groups_users gu on gr.group_id = gu.group_id | |||
inner join projects p on p.id = gr.resource_id | |||
inner join components p on p.id = gr.resource_id | |||
where | |||
p.uuid = #{projectUuid, jdbcType=VARCHAR} and | |||
p.organization_uuid = gr.organization_uuid and | |||
@@ -391,7 +391,7 @@ | |||
gr.role | |||
from | |||
group_roles gr | |||
inner join projects p on | |||
inner join components p on | |||
p.id = gr.resource_id | |||
where | |||
p.uuid = #{projectUuid, jdbcType=VARCHAR} | |||
@@ -440,14 +440,14 @@ | |||
exists ( | |||
select 1 | |||
from user_roles ur | |||
inner join projects p on p.id = ur.resource_id and p.organization_uuid = ur.organization_uuid | |||
inner join components p on p.id = ur.resource_id and p.organization_uuid = ur.organization_uuid | |||
where | |||
p.kee = #{projectKey, jdbcType=VARCHAR} | |||
and ur.role = #{permission, jdbcType=VARCHAR} | |||
and ur.user_id = u.id | |||
) or exists ( | |||
select 1 | |||
from projects p | |||
from components p | |||
inner join group_roles gr on gr.resource_id = p.id and gr.organization_uuid = p.organization_uuid | |||
inner join groups_users gu on gu.group_id = gr.group_id | |||
where | |||
@@ -458,7 +458,7 @@ | |||
<if test="permission == 'user' or permission == 'codeviewer'"> | |||
or exists ( | |||
select 1 | |||
from projects p | |||
from components p | |||
where | |||
p.kee = #{projectKey, jdbcType=VARCHAR} | |||
and p.private = ${_false} |
@@ -85,7 +85,7 @@ | |||
</where> | |||
) sub | |||
left join projects p on sub.componentId = p.id | |||
left join components p on sub.componentId = p.id | |||
<where> | |||
<if test="query.searchQueryToSql != null"> | |||
and lower(sub.name) like #{query.searchQueryToSqlLowercase,jdbcType=VARCHAR} ESCAPE '/' |
@@ -40,7 +40,7 @@ | |||
and ur.resource_id = #{query.componentId,jdbcType=BIGINT} | |||
</otherwise> | |||
</choose> | |||
left join projects p on ur.resource_id = p.id | |||
left join components p on ur.resource_id = p.id | |||
inner join organization_members om on u.id=om.user_id and om.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR} | |||
<where> | |||
<include refid="sqlQueryFilters" /> | |||
@@ -60,7 +60,7 @@ | |||
<sql id="sqlQueryJoins"> | |||
from users u | |||
left join user_roles ur on ur.user_id = u.id | |||
left join projects p on ur.resource_id = p.id | |||
left join components p on ur.resource_id = p.id | |||
inner join organization_members om on u.id=om.user_id and om.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR} | |||
</sql> | |||
@@ -109,7 +109,7 @@ | |||
select ur.resource_id as componentId, ur.role as permission, count(u.login) as count | |||
from users u | |||
inner join user_roles ur on ur.user_id = u.id | |||
inner join projects p on p.id = ur.resource_id | |||
inner join components p on p.id = ur.resource_id | |||
where u.active = ${_true} | |||
and p.id in <foreach collection="projectIds" open="(" close=")" item="projectId" separator=",">#{projectId}</foreach> | |||
group by ur.resource_id, ur.role |
@@ -0,0 +1,144 @@ | |||
<?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.project.ProjectMapper"> | |||
<sql id="projectColumns"> | |||
p.uuid as uuid, | |||
p.organization_uuid as organizationUuid, | |||
p.kee as kee, | |||
p.qualifier as qualifier, | |||
p.name as name, | |||
p.description as description, | |||
p.tags as tagsString, | |||
p.private as isPrivate, | |||
p.created_at as createdAt, | |||
p.updated_at as updatedAt | |||
</sql> | |||
<select id="selectByUuid" parameterType="String" resultType="Project"> | |||
SELECT | |||
<include refid="projectColumns"/> | |||
FROM projects p | |||
where | |||
p.uuid=#{uuid,jdbcType=VARCHAR} | |||
</select> | |||
<select id="selectByUuids" resultType="Project"> | |||
select | |||
<include refid="projectColumns"/> | |||
from projects p | |||
where | |||
p.uuid in | |||
<foreach collection="uuids" open="(" close=")" item="uuid" separator=","> | |||
#{uuid,jdbcType=VARCHAR} | |||
</foreach> | |||
</select> | |||
<select id="selectProjectsByKeys" resultType="Project"> | |||
select | |||
<include refid="projectColumns"/> | |||
from projects p | |||
where | |||
p.qualifier='TRK' and | |||
p.kee in | |||
<foreach collection="kees" open="(" close=")" item="k" separator=","> | |||
#{k,jdbcType=VARCHAR} | |||
</foreach> | |||
</select> | |||
<select id="selectProjects" resultType="Project"> | |||
select | |||
<include refid="projectColumns"/> | |||
from projects p | |||
where | |||
p.qualifier='TRK' | |||
</select> | |||
<select id="selectByOrganizationUuid" parameterType="String" resultType="Project"> | |||
select | |||
<include refid="projectColumns"/> | |||
from projects p | |||
where | |||
p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} | |||
</select> | |||
<select id="selectProjectsByOrganizationUuid" parameterType="String" resultType="Project"> | |||
select | |||
<include refid="projectColumns"/> | |||
from projects p | |||
where | |||
p.qualifier='TRK' and | |||
p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} | |||
</select> | |||
<select id="selectProjectByKey" parameterType="String" resultType="Project"> | |||
SELECT | |||
<include refid="projectColumns"/> | |||
FROM projects p | |||
where | |||
p.qualifier='TRK' and | |||
p.kee=#{key,jdbcType=VARCHAR} | |||
</select> | |||
<select id="selectApplicationByKey" parameterType="String" resultType="Project"> | |||
SELECT | |||
<include refid="projectColumns"/> | |||
FROM projects p | |||
where | |||
p.qualifier='APP' and | |||
p.kee=#{key,jdbcType=VARCHAR} | |||
</select> | |||
<select id="selectProjectOrAppByKey" parameterType="String" resultType="Project"> | |||
SELECT | |||
<include refid="projectColumns"/> | |||
FROM projects p | |||
where | |||
p.kee=#{key,jdbcType=VARCHAR} | |||
</select> | |||
<insert id="insert" parameterType="Project"> | |||
INSERT INTO projects ( | |||
organization_uuid, | |||
kee, | |||
qualifier, | |||
uuid, | |||
name, | |||
description, | |||
private, | |||
tags, | |||
created_at, | |||
updated_at | |||
) | |||
VALUES ( | |||
#{organizationUuid,jdbcType=VARCHAR}, | |||
#{kee,jdbcType=VARCHAR}, | |||
#{qualifier,jdbcType=VARCHAR}, | |||
#{uuid,jdbcType=VARCHAR}, | |||
#{name,jdbcType=VARCHAR}, | |||
#{description,jdbcType=VARCHAR}, | |||
#{isPrivate,jdbcType=BOOLEAN}, | |||
#{tagsString, jdbcType=VARCHAR}, | |||
#{createdAt,jdbcType=BIGINT}, | |||
#{updatedAt,jdbcType=BIGINT} | |||
) | |||
</insert> | |||
<update id="updateTags" parameterType="Project"> | |||
update projects set | |||
tags = #{tagsString,jdbcType=VARCHAR}, | |||
updated_at = #{updatedAt,jdbcType=BIGINT} | |||
where | |||
uuid = #{uuid,jdbcType=VARCHAR} | |||
</update> | |||
<update id="update" parameterType="Project"> | |||
update projects set | |||
name = #{name,jdbcType=VARCHAR}, | |||
description = #{description,jdbcType=VARCHAR}, | |||
updated_at = #{updatedAt,jdbcType=BIGINT} | |||
where | |||
uuid = #{uuid,jdbcType=VARCHAR} | |||
</update> | |||
</mapper> |
@@ -25,7 +25,7 @@ | |||
FROM | |||
internal_component_props icp | |||
JOIN | |||
projects p | |||
components p | |||
ON | |||
icp.component_uuid = p.uuid | |||
<where> |
@@ -23,7 +23,7 @@ | |||
${_false} as "global" | |||
FROM | |||
users u | |||
INNER JOIN projects c on c.kee = #{projectKey,jdbcType=VARCHAR} | |||
INNER JOIN components c on c.kee = #{projectKey,jdbcType=VARCHAR} | |||
INNER JOIN properties p ON p.user_id = u.id | |||
WHERE | |||
p.prop_key = #{notifKey,jdbcType=VARCHAR} | |||
@@ -59,7 +59,7 @@ | |||
u.email as "email" | |||
FROM | |||
users u | |||
INNER JOIN projects c on | |||
INNER JOIN components c on | |||
c.kee = #{projectKey,jdbcType=VARCHAR} | |||
INNER JOIN properties p ON | |||
p.user_id = u.id | |||
@@ -99,7 +99,7 @@ | |||
<include refid="columnsToScrapPropertyDto"/> | |||
from | |||
properties p, | |||
projects r | |||
components r | |||
where | |||
p.resource_id=r.id | |||
and p.user_id is null | |||
@@ -177,7 +177,7 @@ | |||
<include refid="columnsToScrapPropertyDto"/> | |||
from | |||
properties p | |||
inner join projects prj on prj.id=p.resource_id and prj.qualifier = #{qualifier, jdbcType=VARCHAR} | |||
inner join components prj on prj.id=p.resource_id and prj.qualifier = #{qualifier, jdbcType=VARCHAR} | |||
where | |||
p.prop_key = #{key, jdbcType=VARCHAR} | |||
and p.user_id = #{userId, jdbcType=INTEGER} | |||
@@ -204,7 +204,7 @@ | |||
<select id="selectIdsByOrganizationAndUser" parameterType="map" resultType="long"> | |||
select py.id | |||
from properties py | |||
inner join projects ps on py.resource_id = ps.id | |||
inner join components ps on py.resource_id = ps.id | |||
where | |||
py.user_id=#{userId,jdbcType=INTEGER} | |||
and ps.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} | |||
@@ -213,7 +213,7 @@ | |||
<select id="selectIdsByOrganizationAndMatchingLogin" parameterType="String" resultType="long"> | |||
select py.id | |||
from properties py | |||
inner join projects ps on py.resource_id = ps.id | |||
inner join components ps on py.resource_id = ps.id | |||
where | |||
py.text_value like #{login,jdbcType=VARCHAR} | |||
and py.prop_key in |
@@ -66,7 +66,7 @@ | |||
select | |||
p.id, p.uuid | |||
from | |||
projects p | |||
components p | |||
where | |||
( | |||
p.project_uuid=#{rootUuid,jdbcType=VARCHAR} | |||
@@ -82,7 +82,7 @@ | |||
select | |||
file_uuid | |||
from file_sources fs | |||
inner join projects p on | |||
inner join components p on | |||
p.uuid = fs.file_uuid | |||
and p.enabled = ${_false} | |||
and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} | |||
@@ -92,7 +92,7 @@ | |||
select | |||
i.component_uuid | |||
from issues i | |||
inner join projects p on | |||
inner join components p on | |||
p.uuid = i.component_uuid | |||
and p.enabled = ${_false} | |||
and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} | |||
@@ -104,7 +104,7 @@ | |||
select | |||
lm.component_uuid | |||
from live_measures lm | |||
inner join projects p on | |||
inner join components p on | |||
p.uuid = lm.component_uuid | |||
and p.enabled = ${_false} | |||
and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} | |||
@@ -245,13 +245,19 @@ | |||
</delete> | |||
<delete id="deleteComponentsByProjectUuid" parameterType="map"> | |||
delete from projects | |||
delete from components | |||
where | |||
project_uuid = #{rootUuid,jdbcType=VARCHAR} | |||
</delete> | |||
<delete id="deleteComponentsByUuids" parameterType="map"> | |||
<delete id="deleteProjectsByProjectUuid" parameterType="map"> | |||
delete from projects | |||
where | |||
uuid = #{projectUuid,jdbcType=VARCHAR} | |||
</delete> | |||
<delete id="deleteComponentsByUuids" parameterType="map"> | |||
delete from components | |||
where | |||
uuid in | |||
<foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=","> | |||
@@ -340,7 +346,7 @@ | |||
SELECT | |||
p.id, p.uuid | |||
FROM | |||
projects p | |||
components p | |||
WHERE | |||
p.enabled = ${_false} | |||
AND p.project_uuid=#{projectUuid,jdbcType=VARCHAR} |
@@ -3,9 +3,9 @@ | |||
<mapper namespace="org.sonar.db.qualitygate.ProjectQgateAssociationMapper"> | |||
<select id="selectProjects" parameterType="map" resultType="ProjectQgateAssociation"> | |||
<select id="selectProjects" parameterType="map" resultType="ProjectQgateAssociation"> | |||
SELECT proj.id as id, proj.kee as "key", proj.name as name, qg.id as gateId | |||
FROM projects proj | |||
FROM components proj | |||
LEFT JOIN project_qgates prqg ON prqg.project_uuid=proj.uuid AND prqg.quality_gate_uuid = #{query.gateUuid, jdbcType=VARCHAR} | |||
LEFT JOIN quality_gates qg ON qg.uuid = prqg.quality_gate_uuid | |||
where | |||
@@ -28,11 +28,11 @@ | |||
order by proj.name | |||
</select> | |||
<select id="selectQGateUuidByComponentUuid" parameterType="String" resultType="string"> | |||
<select id="selectQGateUuidByProjectUuid" parameterType="String" resultType="string"> | |||
SELECT quality_gate_uuid | |||
FROM project_qgates | |||
<where> | |||
AND project_uuid=#{componentUuid} | |||
AND project_uuid=#{projectUuid} | |||
</where> | |||
</select> | |||
@@ -261,7 +261,7 @@ | |||
<select id="countProjectsByOrganizationAndProfiles" resultType="KeyLongValue" parameterType="map"> | |||
select pqp.profile_key as "key", count(pj.uuid) as "value" | |||
from projects pj | |||
from components pj | |||
inner join project_qprofiles pqp on pqp.project_uuid = pj.uuid | |||
inner join org_qprofiles oqp on oqp.uuid = pqp.profile_key | |||
where | |||
@@ -340,7 +340,7 @@ | |||
pj.kee as projectKey, | |||
pj.name as projectName, | |||
pp.profile_key as profileKey | |||
from projects pj | |||
from components pj | |||
inner join project_qprofiles pp ON pp.project_uuid = pj.uuid and pp.profile_key = #{profileUuid, jdbcType=VARCHAR} | |||
where | |||
pj.scope = 'PRJ' | |||
@@ -353,7 +353,7 @@ | |||
<select id="selectDeselectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto"> | |||
SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey | |||
FROM projects pj | |||
FROM components pj | |||
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid | |||
AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR} | |||
WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null | |||
@@ -365,7 +365,7 @@ | |||
<select id="selectProjectAssociations" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto"> | |||
SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey | |||
FROM projects pj | |||
FROM components pj | |||
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid | |||
AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR} | |||
WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null |
@@ -43,7 +43,7 @@ | |||
p.uuid as uuid, | |||
p.path as path, | |||
fs.line_hashes as rawLineHashes | |||
from projects p | |||
from components p | |||
inner join file_sources fs on | |||
fs.file_uuid = p.uuid | |||
where |
@@ -163,6 +163,54 @@ CREATE TABLE "CE_TASK_MESSAGE"( | |||
ALTER TABLE "CE_TASK_MESSAGE" ADD CONSTRAINT "PK_CE_TASK_MESSAGE" PRIMARY KEY("UUID"); | |||
CREATE INDEX "CE_TASK_MESSAGE_TASK" ON "CE_TASK_MESSAGE"("TASK_UUID"); | |||
CREATE TABLE "COMPONENTS"( | |||
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), | |||
"UUID" VARCHAR(50) NOT NULL, | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"KEE" VARCHAR(400), | |||
"DEPRECATED_KEE" VARCHAR(400), | |||
"NAME" VARCHAR(2000), | |||
"LONG_NAME" VARCHAR(2000), | |||
"DESCRIPTION" VARCHAR(2000), | |||
"ENABLED" BOOLEAN DEFAULT TRUE NOT NULL, | |||
"SCOPE" VARCHAR(3), | |||
"QUALIFIER" VARCHAR(10), | |||
"PRIVATE" BOOLEAN NOT NULL, | |||
"ROOT_UUID" VARCHAR(50) NOT NULL, | |||
"LANGUAGE" VARCHAR(20), | |||
"COPY_COMPONENT_UUID" VARCHAR(50), | |||
"DEVELOPER_UUID" VARCHAR(50), | |||
"PATH" VARCHAR(2000), | |||
"UUID_PATH" VARCHAR(1500) NOT NULL, | |||
"PROJECT_UUID" VARCHAR(50) NOT NULL, | |||
"MODULE_UUID" VARCHAR(50), | |||
"MODULE_UUID_PATH" VARCHAR(1500), | |||
"AUTHORIZATION_UPDATED_AT" BIGINT, | |||
"TAGS" VARCHAR(500), | |||
"MAIN_BRANCH_PROJECT_UUID" VARCHAR(50), | |||
"B_CHANGED" BOOLEAN, | |||
"B_NAME" VARCHAR(500), | |||
"B_LONG_NAME" VARCHAR(500), | |||
"B_DESCRIPTION" VARCHAR(2000), | |||
"B_ENABLED" BOOLEAN, | |||
"B_QUALIFIER" VARCHAR(10), | |||
"B_LANGUAGE" VARCHAR(20), | |||
"B_COPY_COMPONENT_UUID" VARCHAR(50), | |||
"B_PATH" VARCHAR(2000), | |||
"B_UUID_PATH" VARCHAR(1500), | |||
"B_MODULE_UUID" VARCHAR(50), | |||
"B_MODULE_UUID_PATH" VARCHAR(1500), | |||
"CREATED_AT" TIMESTAMP | |||
); | |||
ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID"); | |||
CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID"); | |||
CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE"); | |||
CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID"); | |||
CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID"); | |||
CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER"); | |||
CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID"); | |||
CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID"); | |||
CREATE TABLE "DEFAULT_QPROFILES"( | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"LANGUAGE" VARCHAR(20) NOT NULL, | |||
@@ -658,52 +706,20 @@ ALTER TABLE "PROJECT_QPROFILES" ADD CONSTRAINT "PK_PROJECT_QPROFILES" PRIMARY KE | |||
CREATE UNIQUE INDEX "UNIQ_PROJECT_QPROFILES" ON "PROJECT_QPROFILES"("PROJECT_UUID", "PROFILE_KEY"); | |||
CREATE TABLE "PROJECTS"( | |||
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), | |||
"UUID" VARCHAR(50) NOT NULL, | |||
"UUID" VARCHAR(40) NOT NULL, | |||
"KEE" VARCHAR(400) NOT NULL, | |||
"QUALIFIER" VARCHAR(10) NOT NULL, | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"KEE" VARCHAR(400), | |||
"DEPRECATED_KEE" VARCHAR(400), | |||
"NAME" VARCHAR(2000), | |||
"LONG_NAME" VARCHAR(2000), | |||
"DESCRIPTION" VARCHAR(2000), | |||
"ENABLED" BOOLEAN DEFAULT TRUE NOT NULL, | |||
"SCOPE" VARCHAR(3), | |||
"QUALIFIER" VARCHAR(10), | |||
"PRIVATE" BOOLEAN NOT NULL, | |||
"ROOT_UUID" VARCHAR(50) NOT NULL, | |||
"LANGUAGE" VARCHAR(20), | |||
"COPY_COMPONENT_UUID" VARCHAR(50), | |||
"DEVELOPER_UUID" VARCHAR(50), | |||
"PATH" VARCHAR(2000), | |||
"UUID_PATH" VARCHAR(1500) NOT NULL, | |||
"PROJECT_UUID" VARCHAR(50) NOT NULL, | |||
"MODULE_UUID" VARCHAR(50), | |||
"MODULE_UUID_PATH" VARCHAR(1500), | |||
"AUTHORIZATION_UPDATED_AT" BIGINT, | |||
"TAGS" VARCHAR(500), | |||
"MAIN_BRANCH_PROJECT_UUID" VARCHAR(50), | |||
"B_CHANGED" BOOLEAN, | |||
"B_NAME" VARCHAR(500), | |||
"B_LONG_NAME" VARCHAR(500), | |||
"B_DESCRIPTION" VARCHAR(2000), | |||
"B_ENABLED" BOOLEAN, | |||
"B_QUALIFIER" VARCHAR(10), | |||
"B_LANGUAGE" VARCHAR(20), | |||
"B_COPY_COMPONENT_UUID" VARCHAR(50), | |||
"B_PATH" VARCHAR(2000), | |||
"B_UUID_PATH" VARCHAR(1500), | |||
"B_MODULE_UUID" VARCHAR(50), | |||
"B_MODULE_UUID_PATH" VARCHAR(1500), | |||
"CREATED_AT" TIMESTAMP | |||
"CREATED_AT" BIGINT NOT NULL, | |||
"UPDATED_AT" BIGINT NOT NULL | |||
); | |||
ALTER TABLE "PROJECTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID"); | |||
CREATE INDEX "PROJECTS_ORGANIZATION" ON "PROJECTS"("ORGANIZATION_UUID"); | |||
CREATE UNIQUE INDEX "PROJECTS_KEE" ON "PROJECTS"("KEE"); | |||
CREATE INDEX "PROJECTS_MODULE_UUID" ON "PROJECTS"("MODULE_UUID"); | |||
CREATE INDEX "PROJECTS_PROJECT_UUID" ON "PROJECTS"("PROJECT_UUID"); | |||
CREATE INDEX "PROJECTS_QUALIFIER" ON "PROJECTS"("QUALIFIER"); | |||
CREATE INDEX "PROJECTS_ROOT_UUID" ON "PROJECTS"("ROOT_UUID"); | |||
CREATE INDEX "PROJECTS_UUID" ON "PROJECTS"("UUID"); | |||
ALTER TABLE "PROJECTS" ADD CONSTRAINT "PK_NEW_PROJECTS" PRIMARY KEY("UUID"); | |||
CREATE UNIQUE INDEX "UNIQ_PROJECTS_KEE" ON "PROJECTS"("KEE"); | |||
CREATE INDEX "IDX_QUALIFIER" ON "PROJECTS"("QUALIFIER"); | |||
CREATE TABLE "PROPERTIES"( | |||
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), |
@@ -30,6 +30,6 @@ public class DaoModuleTest { | |||
public void verify_count_of_added_components() { | |||
ComponentContainer container = new ComponentContainer(); | |||
new DaoModule().configure(container); | |||
assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 65); | |||
assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 66); | |||
} | |||
} |
@@ -26,7 +26,7 @@ import org.sonar.api.utils.System2; | |||
import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
@@ -54,8 +54,8 @@ public class ProjectAlmSettingDaoTest { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto githubAlmSettingDto = db.almSettings().insertGitHubAlmSetting(); | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
ComponentDto anotherProject = db.components().insertPrivateProject(); | |||
ProjectDto project = db.components().insertPrivateProjectDto(); | |||
ProjectDto anotherProject = db.components().insertPrivateProjectDto(); | |||
ProjectAlmSettingDto githubProjectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSettingDto, project); | |||
underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto); | |||
@@ -63,7 +63,7 @@ public class ProjectAlmSettingDaoTest { | |||
.extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid, | |||
ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug, | |||
ProjectAlmSettingDto::getCreatedAt, ProjectAlmSettingDto::getUpdatedAt) | |||
.containsExactly(A_UUID, githubAlmSettingDto.getUuid(), project.uuid(), | |||
.containsExactly(A_UUID, githubAlmSettingDto.getUuid(), project.getUuid(), | |||
githubProjectAlmSettingDto.getAlmRepo(), githubProjectAlmSettingDto.getAlmSlug(), | |||
A_DATE, A_DATE); | |||
@@ -75,7 +75,7 @@ public class ProjectAlmSettingDaoTest { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting(); | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
ProjectDto project = db.components().insertPrivateProjectDto(); | |||
ProjectAlmSettingDto projectAlmSettingDto = db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project); | |||
AlmSettingDto anotherGithubAlmSetting = db.almSettings().insertGitHubAlmSetting(); | |||
@@ -87,7 +87,7 @@ public class ProjectAlmSettingDaoTest { | |||
.extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid, | |||
ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug, | |||
ProjectAlmSettingDto::getCreatedAt, ProjectAlmSettingDto::getUpdatedAt) | |||
.containsExactly(projectAlmSettingDto.getUuid(), anotherGithubAlmSetting.getUuid(), project.uuid(), | |||
.containsExactly(projectAlmSettingDto.getUuid(), anotherGithubAlmSetting.getUuid(), project.getUuid(), | |||
newProjectAlmSettingDto.getAlmRepo(), newProjectAlmSettingDto.getAlmSlug(), | |||
A_DATE, A_DATE_LATER); | |||
} | |||
@@ -97,9 +97,9 @@ public class ProjectAlmSettingDaoTest { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting(); | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
ProjectDto project = db.components().insertPrivateProjectDto(); | |||
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project); | |||
ComponentDto anotherProject = db.components().insertPrivateProject(); | |||
ProjectDto anotherProject = db.components().insertPrivateProjectDto(); | |||
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, anotherProject); | |||
underTest.deleteByProject(dbSession, project); | |||
@@ -113,13 +113,13 @@ public class ProjectAlmSettingDaoTest { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting(); | |||
ComponentDto project1 = db.components().insertPrivateProject(); | |||
ComponentDto project2 = db.components().insertPrivateProject(); | |||
ProjectDto project1 = db.components().insertPrivateProjectDto(); | |||
ProjectDto project2 = db.components().insertPrivateProjectDto(); | |||
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project1); | |||
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project2); | |||
AlmSettingDto githubAlmSetting1 = db.almSettings().insertGitHubAlmSetting(); | |||
ComponentDto anotherProject = db.components().insertPrivateProject(); | |||
ProjectDto anotherProject = db.components().insertPrivateProjectDto(); | |||
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting1, anotherProject); | |||
underTest.deleteByAlmSetting(dbSession, githubAlmSetting); |
@@ -22,6 +22,8 @@ package org.sonar.db.component; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import java.util.Collection; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
@@ -31,6 +33,7 @@ import org.sonar.api.impl.utils.TestSystem2; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.protobuf.DbProjectBranches; | |||
import static java.util.Arrays.asList; | |||
@@ -376,6 +379,26 @@ public class BranchDaoTest { | |||
assertThat(underTest.selectByBranchKey(dbSession, "U3", "feature/foo")).isEmpty(); | |||
} | |||
@Test | |||
public void selectByBranchKeys() { | |||
ProjectDto project1 = db.components().insertPrivateProjectDto(); | |||
ProjectDto project2 = db.components().insertPrivateProjectDto(); | |||
ProjectDto project3 = db.components().insertPrivateProjectDto(); | |||
BranchDto branch1 = db.components().insertProjectBranch(project1, b -> b.setKey("branch1")); | |||
BranchDto branch2 = db.components().insertProjectBranch(project2, b -> b.setKey("branch2")); | |||
BranchDto branch3 = db.components().insertProjectBranch(project3, b -> b.setKey("branch3")); | |||
Map<String, String> branchKeysByProjectUuid = new HashMap<>(); | |||
branchKeysByProjectUuid.put(project1.getUuid(), "branch1"); | |||
branchKeysByProjectUuid.put(project2.getUuid(), "branch2"); | |||
branchKeysByProjectUuid.put(project3.getUuid(), "nonexisting"); | |||
List<BranchDto> branchDtos = underTest.selectByBranchKeys(dbSession, branchKeysByProjectUuid); | |||
assertThat(branchDtos).hasSize(2); | |||
assertThat(branchDtos).extracting(BranchDto::getUuid).containsExactlyInAnyOrder(branch1.getUuid(), branch2.getUuid()); | |||
} | |||
@Test | |||
public void selectByComponent() { | |||
BranchDto mainBranch = new BranchDto(); | |||
@@ -451,6 +474,24 @@ public class BranchDaoTest { | |||
assertThat(underTest.selectByUuids(db.getSession(), singletonList("unknown"))).isEmpty(); | |||
} | |||
@Test | |||
public void selectByProjectUuid() { | |||
ComponentDto project1 = db.components().insertPrivateProject(); | |||
ComponentDto project2 = db.components().insertPrivateProject(); | |||
ComponentDto branch1 = db.components().insertProjectBranch(project1); | |||
ComponentDto branch2 = db.components().insertProjectBranch(project1); | |||
ComponentDto branch3 = db.components().insertProjectBranch(project2); | |||
ComponentDto branch4 = db.components().insertProjectBranch(project2); | |||
assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(project1.uuid()))) | |||
.extracting(BranchDto::getUuid) | |||
.containsExactlyInAnyOrder(project1.uuid(), branch1.uuid(), branch2.uuid()); | |||
assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(project2.uuid()))) | |||
.extracting(BranchDto::getUuid) | |||
.containsExactlyInAnyOrder(project2.uuid(), branch3.uuid(), branch4.uuid()); | |||
} | |||
@Test | |||
public void selectByUuid() { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
@@ -460,7 +501,7 @@ public class BranchDaoTest { | |||
assertThat(underTest.selectByUuid(db.getSession(), branch1.uuid()).get()) | |||
.extracting(BranchDto::getUuid) | |||
.isEqualTo(branch1.uuid()); | |||
assertThat(underTest.selectByUuid(db.getSession(), project.uuid())).isNotPresent(); | |||
assertThat(underTest.selectByUuid(db.getSession(), project.uuid())).isPresent(); | |||
assertThat(underTest.selectByUuid(db.getSession(), "unknown")).isNotPresent(); | |||
} | |||
@@ -485,8 +526,8 @@ public class BranchDaoTest { | |||
ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH)); | |||
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH)); | |||
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST)); | |||
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, 0L)).isEqualTo(2); | |||
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, NOW)).isEqualTo(2); | |||
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, 0L)).isEqualTo(3); | |||
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, NOW)).isEqualTo(3); | |||
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, NOW + 100)).isEqualTo(0); | |||
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, 0L)).isEqualTo(1); | |||
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, NOW)).isEqualTo(1); |
@@ -220,7 +220,7 @@ public class ComponentDaoTest { | |||
@Test | |||
public void selectByKeyAndBranch() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch").setBranchType(BRANCH)); | |||
ComponentDto file = db.components().insertComponent(newFileDto(branch)); | |||
@@ -233,7 +233,7 @@ public class ComponentDaoTest { | |||
@Test | |||
public void selectByKeyAndPullRequest() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); | |||
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setKey("my_PR").setBranchType(PULL_REQUEST)); | |||
ComponentDto pullRequestNamedAsMainBranch = db.components().insertProjectBranch(project, b -> b.setKey("master").setBranchType(PULL_REQUEST)); | |||
@@ -299,7 +299,7 @@ public class ComponentDaoTest { | |||
@Test | |||
public void selectByKeysAndBranch() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); | |||
ComponentDto file1 = db.components().insertComponent(newFileDto(branch)); | |||
ComponentDto file2 = db.components().insertComponent(newFileDto(branch)); | |||
@@ -318,9 +318,9 @@ public class ComponentDaoTest { | |||
@Test | |||
public void select_by_keys_and_branches() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); | |||
ComponentDto application = db.components().insertMainBranch(a -> a.setQualifier(APP)); | |||
ComponentDto application = db.components().insertPublicProject(a -> a.setQualifier(APP)); | |||
ComponentDto applicationBranch = db.components().insertProjectBranch(application, b -> b.setKey("my_branch")); | |||
assertThat(underTest.selectByKeysAndBranches(db.getSession(), ImmutableMap.of( | |||
@@ -1059,7 +1059,7 @@ public class ComponentDaoTest { | |||
@Test | |||
public void select_projects_does_not_return_branches() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(project); | |||
assertThat(underTest.selectProjects(dbSession)) | |||
@@ -1089,7 +1089,7 @@ public class ComponentDaoTest { | |||
@Test | |||
public void select_projects_by_organization_does_not_return_branches() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertMainBranch(organization); | |||
ComponentDto project = db.components().insertPublicProject(organization); | |||
ComponentDto branch = db.components().insertProjectBranch(project); | |||
assertThat(underTest.selectProjectsByOrganization(dbSession, organization.getUuid())) | |||
@@ -1153,7 +1153,7 @@ public class ComponentDaoTest { | |||
// the project does not have any analysis | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertMainBranch(organization); | |||
ComponentDto project = db.components().insertPublicProject(organization); | |||
assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10)) | |||
.extracting(ComponentDto::uuid) | |||
.containsOnly(project.uuid()); | |||
@@ -1396,7 +1396,7 @@ public class ComponentDaoTest { | |||
"b_enabled as \"bEnabled\", b_uuid_path as \"bUuidPath\", b_language as \"bLanguage\", b_long_name as \"bLongName\"," + | |||
"b_module_uuid as \"bModuleUuid\", b_module_uuid_path as \"bModuleUuidPath\", b_name as \"bName\", " + | |||
"b_path as \"bPath\", b_qualifier as \"bQualifier\" " + | |||
"from projects where uuid='" + uuid + "'"); | |||
"from components where uuid='" + uuid + "'"); | |||
} | |||
@Test | |||
@@ -1507,7 +1507,7 @@ public class ComponentDaoTest { | |||
@Test | |||
public void selectByQuery_should_not_return_branches() { | |||
ComponentDto main = db.components().insertMainBranch(); | |||
ComponentDto main = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(main); | |||
assertThat(underTest.selectByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY, 0, 2)).hasSize(1); | |||
@@ -1516,7 +1516,7 @@ public class ComponentDaoTest { | |||
@Test | |||
public void countByQuery_should_not_include_branches() { | |||
ComponentDto main = db.components().insertMainBranch(); | |||
ComponentDto main = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(main); | |||
assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY)).isEqualTo(1); | |||
@@ -1616,12 +1616,12 @@ public class ComponentDaoTest { | |||
long aLongTimeAgo = 1_000_000_000L; | |||
long recentTime = 3_000_000_000L; | |||
// project with only a non-main and old analyzed branch | |||
ComponentDto oldProject = db.components().insertMainBranch(); | |||
ComponentDto oldProject = db.components().insertPublicProject(); | |||
ComponentDto oldProjectBranch = db.components().insertProjectBranch(oldProject, newBranchDto(oldProject).setBranchType(BRANCH)); | |||
db.components().insertSnapshot(oldProjectBranch, s -> s.setLast(true).setCreatedAt(aLongTimeAgo)); | |||
// project with only a old main branch and a recent non-main branch | |||
ComponentDto recentProject = db.components().insertMainBranch(); | |||
ComponentDto recentProject = db.components().insertPublicProject(); | |||
ComponentDto recentProjectBranch = db.components().insertProjectBranch(recentProject, newBranchDto(recentProject).setBranchType(BRANCH)); | |||
db.components().insertSnapshot(recentProjectBranch, s -> s.setCreatedAt(recentTime).setLast(true)); | |||
db.components().insertSnapshot(recentProjectBranch, s -> s.setCreatedAt(aLongTimeAgo).setLast(false)); | |||
@@ -1966,20 +1966,20 @@ public class ComponentDaoTest { | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
// project1, not the biggest branch - not returned | |||
final ComponentDto project1 = db.components().insertMainBranch(organizationDto, b -> b.setName("foo")); | |||
final ComponentDto project1 = db.components().insertPrivateProject(organizationDto, b -> b.setName("foo")); | |||
insertMeasure(20d, project1, metric); | |||
// branch of project1 - returned | |||
insertMeasure(30d, db.components().insertProjectBranch(project1, b -> b.setBranchType(BRANCH)), metric); | |||
// project2 - returned | |||
insertMeasure(10d, db.components().insertMainBranch(organizationDto, b -> b.setName("bar")), metric); | |||
insertMeasure(10d, db.components().insertPrivateProject(organizationDto, b -> b.setName("bar")), metric); | |||
// public project - not returned | |||
insertMeasure(11d, db.components().insertMainBranch(organizationDto, b -> b.setPrivate(false)), metric); | |||
insertMeasure(11d, db.components().insertPublicProject(organizationDto, b -> b.setPrivate(false)), metric); | |||
// different org - not returned | |||
insertMeasure(12d, db.components().insertMainBranch(db.organizations().insert()), metric); | |||
insertMeasure(12d, db.components().insertPrivateProject(db.organizations().insert()), metric); | |||
List<ProjectNclocDistributionDto> result = underTest.selectPrivateProjectsWithNcloc(db.getSession(), organizationDto.getUuid()); | |||
@@ -20,6 +20,7 @@ | |||
package org.sonar.db.component; | |||
import com.google.common.base.Strings; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
@@ -63,7 +64,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
underTest.updateKey(dbSession, "B", "struts:core"); | |||
dbSession.commit(); | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects")) | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from components")) | |||
.extracting(t -> t.get("UUID"), t -> t.get("KEE")) | |||
.containsOnly( | |||
Tuple.tuple("A", "org.struts:struts"), | |||
@@ -101,7 +102,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
@Test | |||
public void updateKey_updates_branches_too() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(project); | |||
db.components().insertComponent(newFileDto(branch)); | |||
db.components().insertComponent(newFileDto(branch)); | |||
@@ -122,13 +123,13 @@ public class ComponentKeyUpdaterDaoTest { | |||
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1); | |||
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount); | |||
db.select(dbSession, "select kee from projects") | |||
db.select(dbSession, "select kee from components") | |||
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey))); | |||
} | |||
@Test | |||
public void updateKey_updates_pull_requests_too() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); | |||
db.components().insertComponent(newFileDto(pullRequest)); | |||
db.components().insertComponent(newFileDto(pullRequest)); | |||
@@ -149,13 +150,13 @@ public class ComponentKeyUpdaterDaoTest { | |||
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1); | |||
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount); | |||
db.select(dbSession, "select kee from projects") | |||
db.select(dbSession, "select kee from components") | |||
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey))); | |||
} | |||
@Test | |||
public void bulk_updateKey_updates_branches_too() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(project); | |||
ComponentDto module = db.components().insertComponent(prefixDbKeyWithKey(newModuleDto(branch), project.getKey())); | |||
ComponentDto file1 = db.components().insertComponent(prefixDbKeyWithKey(newFileDto(module), module.getKey())); | |||
@@ -177,7 +178,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1); | |||
String newBranchKey = ComponentDto.generateBranchKey(newProjectKey, branch.getBranch()); | |||
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount); | |||
db.select(dbSession, "select kee from projects") | |||
db.select(dbSession, "select kee from components") | |||
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey))); | |||
assertThat(rekeyedResources) | |||
@@ -193,7 +194,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
@Test | |||
public void bulk_updateKey_on_branch_containing_slash() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch/with/slash")); | |||
String newKey = "newKey"; | |||
@@ -205,7 +206,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
@Test | |||
public void bulk_updateKey_updates_pull_requests_too() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); | |||
ComponentDto module = db.components().insertComponent(prefixDbKeyWithKey(newModuleDto(pullRequest), project.getKey())); | |||
ComponentDto file1 = db.components().insertComponent(prefixDbKeyWithKey(newFileDto(module), module.getKey())); | |||
@@ -227,7 +228,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1); | |||
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newPullRequestKey)).hasSize(branchComponentCount); | |||
db.select(dbSession, "select kee from projects") | |||
db.select(dbSession, "select kee from components") | |||
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey))); | |||
assertThat(rekeyedResources) | |||
@@ -277,7 +278,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
underTest.bulkUpdateKey(dbSession, "A", "org.struts", "org.apache.struts", doNotReturnAnyRekeyedResource()); | |||
dbSession.commit(); | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects")) | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from components")) | |||
.extracting(t -> t.get("UUID"), t -> t.get("KEE")) | |||
.containsOnly( | |||
Tuple.tuple("A", "org.apache.struts:struts"), | |||
@@ -297,7 +298,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
underTest.bulkUpdateKey(dbSession, "A", "struts-ui", "struts-web", doNotReturnAnyRekeyedResource()); | |||
dbSession.commit(); | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects")) | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from components")) | |||
.extracting(t -> t.get("UUID"), t -> t.get("KEE")) | |||
.containsOnly( | |||
Tuple.tuple("A", "org.struts:struts"), | |||
@@ -336,7 +337,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
underTest.bulkUpdateKey(dbSession, "A", "org.struts", "org.apache.struts", doNotReturnAnyRekeyedResource()); | |||
dbSession.commit(); | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects")) | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from components")) | |||
.extracting(t -> t.get("UUID"), t -> t.get("KEE")) | |||
.containsOnly( | |||
Tuple.tuple("A", "org.apache.struts:struts"), |
@@ -280,9 +280,9 @@ public class SnapshotDaoTest { | |||
public void selectFinishedByComponentUuidsAndFromDates() { | |||
long from = 1_500_000_000_000L; | |||
long otherFrom = 1_200_000_000_000L; | |||
ComponentDto firstProject = db.components().insertMainBranch(); | |||
ComponentDto secondProject = db.components().insertMainBranch(); | |||
ComponentDto thirdProject = db.components().insertMainBranch(); | |||
ComponentDto firstProject = db.components().insertPublicProject(); | |||
ComponentDto secondProject = db.components().insertPublicProject(); | |||
ComponentDto thirdProject = db.components().insertPublicProject(); | |||
SnapshotDto finishedAnalysis = db.components().insertSnapshot(firstProject, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from)); | |||
insertActivity(firstProject.uuid(), finishedAnalysis, SUCCESS); | |||
SnapshotDto otherFinishedAnalysis = db.components().insertSnapshot(firstProject, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from + 1_000_000L)); | |||
@@ -305,7 +305,7 @@ public class SnapshotDaoTest { | |||
@Test | |||
public void selectFinishedByComponentUuidsAndFromDates_returns_processed_analysis_even_if_analysis_failed() { | |||
long from = 1_500_000_000_000L; | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
SnapshotDto unprocessedAnalysis = db.components().insertSnapshot(project, s -> s.setStatus(STATUS_UNPROCESSED).setCreatedAt(from + 1_000_000L)); | |||
insertActivity(project.uuid(), unprocessedAnalysis, CANCELED); | |||
SnapshotDto finishedAnalysis = db.components().insertSnapshot(project, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from)); | |||
@@ -322,7 +322,7 @@ public class SnapshotDaoTest { | |||
@Test | |||
public void selectFinishedByComponentUuidsAndFromDates_return_branches_analysis() { | |||
long from = 1_500_000_000_000L; | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto firstBranch = db.components().insertProjectBranch(project); | |||
ComponentDto secondBranch = db.components().insertProjectBranch(project); | |||
SnapshotDto finishedAnalysis = db.components().insertSnapshot(firstBranch, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from)); |
@@ -193,7 +193,7 @@ public class IssueDaoTest { | |||
@Test | |||
public void selectOpenByComponentUuid() { | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto projectBranch = db.components().insertProjectBranch(project, | |||
b -> b.setKey("feature/foo") | |||
.setBranchType(BranchType.BRANCH)); | |||
@@ -215,7 +215,7 @@ public class IssueDaoTest { | |||
@Test | |||
public void selectOpenByComponentUuid_should_correctly_map_required_fields() { | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto projectBranch = db.components().insertProjectBranch(project, | |||
b -> b.setKey("feature/foo") | |||
.setBranchType(BranchType.BRANCH)); |
@@ -274,15 +274,15 @@ public class LiveMeasureDaoTest { | |||
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); | |||
MetricDto lines = db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString())); | |||
ComponentDto simpleProject = db.components().insertMainBranch(organization); | |||
ComponentDto simpleProject = db.components().insertPublicProject(organization); | |||
db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d)); | |||
ComponentDto projectWithBiggerBranch = db.components().insertMainBranch(organization); | |||
ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(organization); | |||
ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH)); | |||
db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d)); | |||
db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d)); | |||
ComponentDto projectWithLinesButNoLoc = db.components().insertMainBranch(organization); | |||
ComponentDto projectWithLinesButNoLoc = db.components().insertPublicProject(organization); | |||
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d)); | |||
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d)); | |||
@@ -313,15 +313,15 @@ public class LiveMeasureDaoTest { | |||
OrganizationDto organization = db.organizations().insert(); | |||
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); | |||
ComponentDto simpleProject = db.components().insertMainBranch(organization); | |||
ComponentDto simpleProject = db.components().insertPublicProject(organization); | |||
db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d)); | |||
ComponentDto projectWithBiggerBranch = db.components().insertMainBranch(organization); | |||
ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(organization); | |||
ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH)); | |||
db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d)); | |||
db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d)); | |||
ComponentDto projectToExclude = db.components().insertMainBranch(organization); | |||
ComponentDto projectToExclude = db.components().insertPublicProject(organization); | |||
ComponentDto projectToExcludeBranch = db.components().insertProjectBranch(projectToExclude, b -> b.setBranchType(BranchType.BRANCH)); | |||
db.measures().insertLiveMeasure(projectToExclude, ncloc, m -> m.setValue(300d)); | |||
db.measures().insertLiveMeasure(projectToExcludeBranch, ncloc, m -> m.setValue(400d)); |
@@ -22,6 +22,7 @@ package org.sonar.db.measure; | |||
import com.google.common.collect.Maps; | |||
import java.util.Map; | |||
import javax.annotation.Nullable; | |||
import org.junit.Ignore; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
@@ -206,7 +207,7 @@ public class ProjectMeasuresIndexerIteratorTest { | |||
@Test | |||
public void return_project_without_analysis() { | |||
ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); | |||
ComponentDto project = dbTester.components().insertPrivateProject(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); | |||
dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setLast(false)); | |||
dbSession.commit(); | |||
@@ -218,6 +219,8 @@ public class ProjectMeasuresIndexerIteratorTest { | |||
} | |||
@Test | |||
@Ignore | |||
//TODO | |||
public void does_not_return_non_active_projects() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
// Disabled project |
@@ -308,7 +308,7 @@ public class OrganizationDaoTest { | |||
assertThat(underTest.selectByUuids( | |||
dbSession, | |||
of(ORGANIZATION_DTO_1.getUuid().toUpperCase(Locale.ENGLISH), ORGANIZATION_DTO_2.getUuid().toUpperCase(Locale.ENGLISH)))) | |||
.isEmpty(); | |||
.isEmpty(); | |||
} | |||
@Test | |||
@@ -333,7 +333,7 @@ public class OrganizationDaoTest { | |||
insertOrganization(ORGANIZATION_DTO_1); | |||
insertOrgAlmBinding(ORGANIZATION_DTO_1, GITHUB, "123456"); | |||
assertThat(underTest.selectByOrganizationAlmId(dbSession, GITHUB,"unknown")).isEmpty(); | |||
assertThat(underTest.selectByOrganizationAlmId(dbSession, GITHUB, "unknown")).isEmpty(); | |||
} | |||
@Test | |||
@@ -1027,12 +1027,11 @@ public class OrganizationDaoTest { | |||
OrganizationDto org1 = db.organizations().insert(); | |||
// private project with highest ncloc in non-main branch | |||
ComponentDto project1 = db.components().insertMainBranch(org1); | |||
ComponentDto project1 = db.components().insertPrivateProject(org1); | |||
ComponentDto project1Branch = db.components().insertProjectBranch(project1); | |||
db.measures().insertLiveMeasure(project1, ncloc, m -> m.setValue(1_000.0)); | |||
db.measures().insertLiveMeasure(project1Branch, ncloc, m -> m.setValue(110_000.0)); | |||
// public project that must be ignored | |||
ComponentDto project2 = db.components().insertPublicProject(org1); | |||
ComponentDto project2Branch = db.components().insertProjectBranch(project2); | |||
@@ -1213,15 +1212,15 @@ public class OrganizationDaoTest { | |||
private int insertPrivateProjectsWithBranches(OrganizationDto org, MetricDto ncloc) { | |||
// private project | |||
ComponentDto project1 = db.components().insertMainBranch(org); | |||
ComponentDto project1 = db.components().insertPrivateProject(org); | |||
return Math.max( | |||
// Create the ncloc on main branch | |||
insertLiveMeasures(project1, ncloc, 0), | |||
// Create 5 branches and set the ncloc on them | |||
IntStream.range(1, 5) | |||
.map(i -> insertLiveMeasures(db.components().insertProjectBranch(project1), ncloc, 0)) | |||
.max().orElse(0) | |||
.map(i -> insertLiveMeasures(db.components().insertProjectBranch(project1), ncloc, 0)) | |||
.max().orElse(0) | |||
); | |||
} | |||
@@ -0,0 +1,172 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.project; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.HashSet; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2; | |||
import org.sonar.api.resources.Qualifiers; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbTester; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class ProjectDaoTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private System2 system2 = new AlwaysIncreasingSystem2(1000L); | |||
@Rule | |||
public DbTester db = DbTester.create(system2); | |||
private ProjectDao projectDao = new ProjectDao(); | |||
@Test | |||
public void should_insert_and_select_by_uuid() { | |||
ProjectDto dto = createProject("o1", "p1"); | |||
projectDao.insert(db.getSession(), dto); | |||
Optional<ProjectDto> projectByUuid = projectDao.selectByUuid(db.getSession(), "uuid_o1_p1"); | |||
assertThat(projectByUuid).isPresent(); | |||
assertProject(projectByUuid.get(), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2"); | |||
assertThat(projectByUuid.get().isPrivate()).isTrue(); | |||
} | |||
@Test | |||
public void select_project_by_key() { | |||
ProjectDto dto = createProject("o1", "p1"); | |||
projectDao.insert(db.getSession(), dto); | |||
Optional<ProjectDto> projectByKee = projectDao.selectProjectByKey(db.getSession(), "projectKee_o1_p1"); | |||
assertThat(projectByKee).isPresent(); | |||
assertProject(projectByKee.get(), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2"); | |||
} | |||
@Test | |||
public void select_projects() { | |||
ProjectDto dto1 = createProject("o1", "p1"); | |||
ProjectDto dto2 = createProject("o1", "p2"); | |||
projectDao.insert(db.getSession(), dto1); | |||
projectDao.insert(db.getSession(), dto2); | |||
List<ProjectDto> projects = projectDao.selectProjects(db.getSession()); | |||
assertThat(projects).extracting(ProjectDto::getKey).containsExactlyInAnyOrder("projectKee_o1_p1", "projectKee_o1_p2"); | |||
} | |||
@Test | |||
public void select_by_organization_uuid() { | |||
ProjectDto dto1 = createProject("o1", "p1"); | |||
ProjectDto dto2 = createProject("o1", "p2"); | |||
ProjectDto dto3 = createProject("o2", "p1"); | |||
projectDao.insert(db.getSession(), dto1); | |||
projectDao.insert(db.getSession(), dto2); | |||
projectDao.insert(db.getSession(), dto3); | |||
List<ProjectDto> projectsByOrg = projectDao.selectByOrganizationUuid(db.getSession(), "org_o1"); | |||
assertThat(projectsByOrg).hasSize(2); | |||
assertProject(projectsByOrg.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2"); | |||
assertProject(projectsByOrg.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2"); | |||
} | |||
@Test | |||
public void update_tags() { | |||
ProjectDto dto1 = createProject("o1", "p1").setTagsString(""); | |||
ProjectDto dto2 = createProject("o1", "p2").setTagsString("tag1,tag2"); | |||
projectDao.insert(db.getSession(), dto1); | |||
projectDao.insert(db.getSession(), dto2); | |||
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | |||
assertThat(projectsByUuids).hasSize(2); | |||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", null); | |||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2"); | |||
dto1.setTags(Collections.singletonList("tag3")); | |||
dto2.setTagsString(""); | |||
projectDao.updateTags(db.getSession(), dto1); | |||
projectDao.updateTags(db.getSession(), dto2); | |||
projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | |||
assertThat(projectsByUuids).hasSize(2); | |||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag3"); | |||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", null); | |||
assertThat(projectsByUuids.get(0).getTags()).containsOnly("tag3"); | |||
} | |||
@Test | |||
public void select_by_uuids() { | |||
ProjectDto dto1 = createProject("o1", "p1"); | |||
ProjectDto dto2 = createProject("o1", "p2"); | |||
ProjectDto dto3 = createProject("o1", "p3"); | |||
projectDao.insert(db.getSession(), dto1); | |||
projectDao.insert(db.getSession(), dto2); | |||
projectDao.insert(db.getSession(), dto3); | |||
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); | |||
assertThat(projectsByUuids).hasSize(2); | |||
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2"); | |||
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2"); | |||
} | |||
@Test | |||
public void select_empty_by_uuids() { | |||
ProjectDto dto1 = createProject("o1", "p1"); | |||
ProjectDto dto2 = createProject("o1", "p2"); | |||
ProjectDto dto3 = createProject("o1", "p3"); | |||
projectDao.insert(db.getSession(), dto1); | |||
projectDao.insert(db.getSession(), dto2); | |||
projectDao.insert(db.getSession(), dto3); | |||
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), Collections.emptySet()); | |||
assertThat(projectsByUuids).hasSize(0); | |||
} | |||
private void assertProject(ProjectDto dto, String name, String kee, String org, String uuid, String desc, @Nullable String tags) { | |||
assertThat(dto).extracting("name", "kee", "key", "organizationUuid", "uuid", "description", "tagsString") | |||
.containsExactly(name, kee, kee, org, uuid, desc, tags); | |||
} | |||
private ProjectDto createProject(String org, String name) { | |||
return new ProjectDto() | |||
.setName("projectName_" + name) | |||
.setKey("projectKee_" + org + "_" + name) | |||
.setQualifier(Qualifiers.PROJECT) | |||
.setOrganizationUuid("org_" + org) | |||
.setUuid("uuid_" + org + "_" + name) | |||
.setTags(Arrays.asList("tag1", "tag2")) | |||
.setDescription("desc_" + name) | |||
.setPrivate(true); | |||
} | |||
} |
@@ -29,7 +29,6 @@ import java.util.function.Consumer; | |||
import java.util.stream.IntStream; | |||
import java.util.stream.Stream; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
@@ -49,6 +48,7 @@ import org.sonar.db.newcodeperiod.NewCodePeriodType; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.permission.OrganizationPermission; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.db.user.GroupDto; | |||
import org.sonar.db.user.UserDto; | |||
@@ -82,11 +82,6 @@ public class PurgeCommandsTest { | |||
dbTester.executeUpdateSql("DELETE FROM analysis_properties"); | |||
} | |||
@Before | |||
public void setUp() { | |||
} | |||
/** | |||
* Test that SQL queries execution do not fail with a huge number of parameter | |||
*/ | |||
@@ -218,7 +213,30 @@ public class PurgeCommandsTest { | |||
underTest.deleteComponents(component.uuid()); | |||
assertThat(dbTester.countRowsOfTable("components")).isZero(); | |||
assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); | |||
assertThat(dbTester.countRowsOfTable("events")).isEqualTo(1); | |||
assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1); | |||
assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1); | |||
} | |||
@Test | |||
public void deleteProjects() { | |||
ComponentDto project = dbTester.components().insertPrivateProject(); | |||
ProjectDto projectDto = dbTester.getDbClient().projectDao().selectProjectByKey(dbTester.getSession(), project.getDbKey()).get(); | |||
ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); | |||
SnapshotDto analysis = dbTester.components().insertSnapshot(project); | |||
dbTester.events().insertEvent(analysis); | |||
IssueDto issue = dbTester.issues().insert(dbTester.rules().insert(), project, file); | |||
dbTester.issues().insertChange(issue); | |||
assertThat(dbTester.countRowsOfTable("projects")).isOne(); | |||
underTest.deleteComponents(project.uuid()); | |||
underTest.deleteProject(project.uuid()); | |||
assertThat(dbTester.countRowsOfTable("projects")).isZero(); | |||
assertThat(dbTester.countRowsOfTable("components")).isZero(); | |||
assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); | |||
assertThat(dbTester.countRowsOfTable("events")).isEqualTo(1); | |||
assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1); | |||
@@ -644,7 +662,7 @@ public class PurgeCommandsTest { | |||
} | |||
private int countComponentOfRoot(ComponentDto projectOrView) { | |||
return dbTester.countSql("select count(1) from projects where project_uuid='" + projectOrView.uuid() + "'"); | |||
return dbTester.countSql("select count(1) from components where project_uuid='" + projectOrView.uuid() + "'"); | |||
} | |||
private void insertDuplication(ComponentDto project, SnapshotDto analysis) { |
@@ -75,6 +75,7 @@ import org.sonar.db.metric.MetricDto; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDto; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodType; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.property.PropertyDto; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.db.source.FileSourceDto; | |||
@@ -140,7 +141,7 @@ public class PurgeDaoTest { | |||
public void purge_inactive_branches() { | |||
when(system2.now()).thenReturn(new Date().getTime()); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branch1 = db.components().insertProjectBranch(project); | |||
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH)); | |||
@@ -157,14 +158,15 @@ public class PurgeDaoTest { | |||
underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, project.uuid(), project.uuid()), PurgeListener.EMPTY, new PurgeProfiler()); | |||
dbSession.commit(); | |||
assertThat(uuidsIn("projects")).containsOnly(project.uuid(), branch1.uuid(), branch2.uuid()); | |||
assertThat(uuidsIn("components")).containsOnly(project.uuid(), branch1.uuid(), branch2.uuid()); | |||
assertThat(uuidsIn("projects")).containsOnly(project.uuid()); | |||
} | |||
@Test | |||
public void purge_inactive_pull_request() { | |||
when(system2.now()).thenReturn(new Date().getTime()); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto nonMainBranch = db.components().insertProjectBranch(project); | |||
ComponentDto recentPullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST)); | |||
@@ -181,14 +183,15 @@ public class PurgeDaoTest { | |||
underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, project.uuid(), project.uuid()), PurgeListener.EMPTY, new PurgeProfiler()); | |||
dbSession.commit(); | |||
assertThat(uuidsIn("projects")).containsOnly(project.uuid(), nonMainBranch.uuid(), recentPullRequest.uuid()); | |||
assertThat(uuidsIn("components")).containsOnly(project.uuid(), nonMainBranch.uuid(), recentPullRequest.uuid()); | |||
assertThat(uuidsIn("projects")).containsOnly(project.uuid()); | |||
} | |||
@Test | |||
public void purge_inactive_branches_when_analyzing_non_main_branch() { | |||
when(system2.now()).thenReturn(new Date().getTime()); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto nonMainBranch = db.components().insertProjectBranch(project); | |||
when(system2.now()).thenReturn(DateUtils.addDays(new Date(), -31).getTime()); | |||
@@ -208,7 +211,8 @@ public class PurgeDaoTest { | |||
dbSession.commit(); | |||
// branch1 wasn't deleted since it was being analyzed! | |||
assertThat(uuidsIn("projects")).containsOnly(project.uuid(), nonMainBranch.uuid(), branch1.uuid()); | |||
assertThat(uuidsIn("components")).containsOnly(project.uuid(), nonMainBranch.uuid(), branch1.uuid()); | |||
assertThat(uuidsIn("projects")).containsOnly(project.uuid()); | |||
} | |||
@Test | |||
@@ -249,16 +253,10 @@ public class PurgeDaoTest { | |||
tuple(metricWithoutHistory.getId(), otherOldAnalysis.getUuid())); | |||
} | |||
private Stream<Long> idsOf(String tableName) { | |||
return db.select("select id as \"ID\" from " + tableName) | |||
.stream() | |||
.map(t -> (Long) t.get("ID")); | |||
} | |||
@Test | |||
public void close_issues_clean_index_and_file_sources_of_disabled_components_specified_by_uuid_in_configuration() { | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
db.components().insertSnapshot(project); | |||
db.components().insertSnapshot(project); | |||
db.components().insertSnapshot(project, s -> s.setLast(false)); | |||
@@ -374,7 +372,7 @@ public class PurgeDaoTest { | |||
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectA, null); | |||
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectB, null); | |||
BranchDto branchProjectA = newBranchDto(referencedProjectA); | |||
ComponentDto cptBranchProjectA = ComponentTesting.newProjectBranch(referencedProjectA, branchProjectA); | |||
ComponentDto cptBranchProjectA = ComponentTesting.newBranchComponent(referencedProjectA, branchProjectA); | |||
db.events().insertEventComponentChanges(projectEvent2, projectAnalysis2, randomChangeCategory(), cptBranchProjectA, branchProjectA); | |||
// note: projectEvent3 has no component change | |||
@@ -473,7 +471,7 @@ public class PurgeDaoTest { | |||
@Test | |||
public void selectPurgeableAnalyses_does_not_return_the_baseline() { | |||
ComponentDto project1 = db.components().insertMainBranch(db.getDefaultOrganization(), "master"); | |||
ComponentDto project1 = db.components().insertPublicProject(db.getDefaultOrganization(), "master"); | |||
SnapshotDto analysis1 = db.components().insertSnapshot(newSnapshot() | |||
.setComponentUuid(project1.uuid()) | |||
.setStatus(STATUS_PROCESSED) | |||
@@ -499,7 +497,7 @@ public class PurgeDaoTest { | |||
@Test | |||
public void selectPurgeableAnalyses_does_not_return_the_baseline_of_specific_branch() { | |||
ComponentDto project = db.components().insertMainBranch(db.getDefaultOrganization(), "master"); | |||
ComponentDto project = db.components().insertPublicProject(db.getDefaultOrganization(), "master"); | |||
SnapshotDto analysisProject = db.components().insertSnapshot(newSnapshot() | |||
.setComponentUuid(project.uuid()) | |||
.setStatus(STATUS_PROCESSED) | |||
@@ -563,7 +561,8 @@ public class PurgeDaoTest { | |||
underTest.deleteProject(dbSession, project.uuid()); | |||
dbSession.commit(); | |||
assertThat(uuidsIn("projects")).containsOnly(otherProject.uuid(), otherModule.uuid(), otherDirectory.uuid(), otherFile.uuid()); | |||
assertThat(uuidsIn("components")).containsOnly(otherProject.uuid(), otherModule.uuid(), otherDirectory.uuid(), otherFile.uuid()); | |||
assertThat(uuidsIn("projects")).containsOnly(otherProject.uuid()); | |||
assertThat(uuidsIn("snapshots")).containsOnly(otherAnalysis.getUuid()); | |||
assertThat(uuidsIn("issues", "kee")).containsOnly(otherIssue1.getKey(), otherIssue2.getKey()); | |||
assertThat(uuidsIn("issue_changes", "kee")).containsOnly(otherIssueChange1.getKey()); | |||
@@ -573,21 +572,17 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_webhooks_from_project() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project1 = db.components().insertPrivateProject(organization); | |||
ProjectDto project1 = db.components().insertPrivateProjectDto(organization); | |||
WebhookDto webhook = db.webhooks().insertWebhook(project1); | |||
db.webhookDelivery().insert(webhook); | |||
ComponentDto projectNotToBeDeleted = db.components().insertPrivateProject(organization); | |||
ProjectDto projectNotToBeDeleted = db.components().insertPrivateProjectDto(organization); | |||
WebhookDto webhookNotDeleted = db.webhooks().insertWebhook(projectNotToBeDeleted); | |||
WebhookDeliveryLiteDto webhookDeliveryNotDeleted = db.webhookDelivery().insert(webhookNotDeleted); | |||
underTest.deleteProject(dbSession, project1.uuid()); | |||
underTest.deleteProject(dbSession, project1.getUuid()); | |||
assertThat(db.select(db.getSession(), "select uuid as \"uuid\" from webhooks")) | |||
.extracting(m -> m.get("uuid")) | |||
.containsExactlyInAnyOrder(webhookNotDeleted.getUuid()); | |||
assertThat(db.select(db.getSession(), "select uuid as \"uuid\" from webhook_deliveries")) | |||
.extracting(m -> m.get("uuid")) | |||
.containsExactlyInAnyOrder(webhookDeliveryNotDeleted.getUuid()); | |||
assertThat(uuidsIn("webhooks")).containsOnly(webhookNotDeleted.getUuid()); | |||
assertThat(uuidsIn("webhook_deliveries")).containsOnly(webhookDeliveryNotDeleted.getUuid()); | |||
} | |||
private Stream<String> uuidsOfTable(String tableName) { | |||
@@ -618,8 +613,8 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_activity_when_deleting_project() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
@@ -650,8 +645,8 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_activity_when_deleting_project() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
@@ -682,8 +677,8 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_activity_when_deleting_project() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
@@ -714,8 +709,8 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_activity_when_deleting_project() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
@@ -765,8 +760,8 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_queue_when_deleting_project() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
@@ -797,8 +792,8 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_queue_when_deleting_project() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
@@ -830,8 +825,8 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_queue_when_deleting_project() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
@@ -863,8 +858,8 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_queue_when_deleting_project() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
@@ -896,8 +891,8 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_row_in_events_and_event_component_changes_when_deleting_project() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project)); | |||
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); | |||
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); | |||
SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project); | |||
@@ -918,7 +913,7 @@ public class PurgeDaoTest { | |||
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectA, null); | |||
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectB, null); | |||
BranchDto branchProjectA = newBranchDto(referencedProjectA); | |||
ComponentDto cptBranchProjectA = ComponentTesting.newProjectBranch(referencedProjectA, branchProjectA); | |||
ComponentDto cptBranchProjectA = ComponentTesting.newBranchComponent(referencedProjectA, branchProjectA); | |||
db.events().insertEventComponentChanges(projectEvent2, projectAnalysis2, randomChangeCategory(), cptBranchProjectA, branchProjectA); | |||
// note: projectEvent3 has no component change | |||
db.events().insertEventComponentChanges(branchEvent1, branchAnalysis1, randomChangeCategory(), referencedProjectB, null); | |||
@@ -957,7 +952,7 @@ public class PurgeDaoTest { | |||
private ComponentDto insertProjectWithBranchAndRelatedData() { | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto branch = db.components().insertProjectBranch(project); | |||
ComponentDto module = db.components().insertComponent(newModuleDto(branch)); | |||
ComponentDto subModule = db.components().insertComponent(newModuleDto(module)); | |||
@@ -971,19 +966,19 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_branch_content_when_deleting_project() { | |||
ComponentDto anotherLivingProject = insertProjectWithBranchAndRelatedData(); | |||
int projectEntryCount = db.countRowsOfTable("projects"); | |||
int projectEntryCount = db.countRowsOfTable("components"); | |||
int issueCount = db.countRowsOfTable("issues"); | |||
int branchCount = db.countRowsOfTable("project_branches"); | |||
ComponentDto projectToDelete = insertProjectWithBranchAndRelatedData(); | |||
assertThat(db.countRowsOfTable("projects")).isGreaterThan(projectEntryCount); | |||
assertThat(db.countRowsOfTable("components")).isGreaterThan(projectEntryCount); | |||
assertThat(db.countRowsOfTable("issues")).isGreaterThan(issueCount); | |||
assertThat(db.countRowsOfTable("project_branches")).isGreaterThan(branchCount); | |||
underTest.deleteProject(dbSession, projectToDelete.uuid()); | |||
dbSession.commit(); | |||
assertThat(db.countRowsOfTable("projects")).isEqualTo(projectEntryCount); | |||
assertThat(db.countRowsOfTable("components")).isEqualTo(projectEntryCount); | |||
assertThat(db.countRowsOfTable("issues")).isEqualTo(issueCount); | |||
assertThat(db.countRowsOfTable("project_branches")).isEqualTo(branchCount); | |||
} | |||
@@ -1001,7 +996,7 @@ public class PurgeDaoTest { | |||
underTest.deleteProject(dbSession, view.uuid()); | |||
dbSession.commit(); | |||
assertThat(uuidsIn("projects")) | |||
assertThat(uuidsIn("components")) | |||
.containsOnly(project.uuid(), otherView.uuid(), otherSubView.uuid(), otherProjectCopy.uuid()); | |||
} | |||
@@ -1052,7 +1047,7 @@ public class PurgeDaoTest { | |||
@Test | |||
public void should_delete_old_closed_issues() { | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto project = db.components().insertPublicProject(); | |||
ComponentDto module = db.components().insertComponent(newModuleDto(project)); | |||
ComponentDto file = db.components().insertComponent(newFileDto(module)); | |||
@@ -1083,7 +1078,7 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_disabled_components_without_issues() { | |||
ComponentDto project = db.components().insertMainBranch(p -> p.setEnabled(true)); | |||
ComponentDto project = db.components().insertPublicProject(p -> p.setEnabled(true)); | |||
ComponentDto enabledFileWithIssues = db.components().insertComponent(newFileDto(project).setEnabled(true)); | |||
ComponentDto disabledFileWithIssues = db.components().insertComponent(newFileDto(project).setEnabled(false)); | |||
ComponentDto enabledFileWithoutIssues = db.components().insertComponent(newFileDto(project).setEnabled(true)); | |||
@@ -1175,7 +1170,7 @@ public class PurgeDaoTest { | |||
@Test | |||
public void delete_ce_analysis_older_than_180_and_scanner_context_older_than_40_days_of_project_and_branches_when_purging_project() { | |||
LocalDateTime now = LocalDateTime.now(); | |||
ComponentDto project1 = db.components().insertMainBranch(); | |||
ComponentDto project1 = db.components().insertPublicProject(); | |||
ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setExcludeFromPurge(true)); | |||
Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid()); | |||
Consumer<CeQueueDto> belongsToBranch1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(branch1.uuid()); | |||
@@ -1378,7 +1373,7 @@ public class PurgeDaoTest { | |||
} | |||
@Test | |||
public void deleteNonRootComponents_deletes_only_non_root_components_of_a_project_from_table_PROJECTS() { | |||
public void deleteNonRootComponents_deletes_only_non_root_components_of_a_project_from_table_components() { | |||
ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject() : db.components().insertPrivateProject(); | |||
ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)); | |||
ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1)); | |||
@@ -1397,12 +1392,12 @@ public class PurgeDaoTest { | |||
underTest.deleteNonRootComponentsInView(dbSession, components); | |||
assertThat(uuidsIn("projects")) | |||
assertThat(uuidsIn(" components")) | |||
.containsOnly(project.uuid()); | |||
} | |||
@Test | |||
public void deleteNonRootComponents_deletes_only_non_root_components_of_a_view_from_table_PROJECTS() { | |||
public void deleteNonRootComponents_deletes_only_non_root_components_of_a_view_from_table_components() { | |||
ComponentDto[] projects = { | |||
db.components().insertPrivateProject(), | |||
db.components().insertPrivateProject(), | |||
@@ -1423,12 +1418,12 @@ public class PurgeDaoTest { | |||
underTest.deleteNonRootComponentsInView(dbSession, components); | |||
assertThat(uuidsIn("projects")) | |||
assertThat(uuidsIn(" components")) | |||
.containsOnly(view.uuid(), projects[0].uuid(), projects[1].uuid(), projects[2].uuid()); | |||
} | |||
@Test | |||
public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_project_from_table_PROJECTS() { | |||
public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_project_from_table_components() { | |||
ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject() : db.components().insertPrivateProject(); | |||
ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)); | |||
ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1)); | |||
@@ -1439,16 +1434,16 @@ public class PurgeDaoTest { | |||
ComponentDto file3 = db.components().insertComponent(newFileDto(project)); | |||
underTest.deleteNonRootComponentsInView(dbSession, singletonList(file3)); | |||
assertThat(uuidsIn("projects")) | |||
assertThat(uuidsIn("components")) | |||
.containsOnly(project.uuid(), module1.uuid(), module2.uuid(), dir1.uuid(), dir2.uuid(), file1.uuid(), file2.uuid()); | |||
underTest.deleteNonRootComponentsInView(dbSession, asList(module1, dir2, file1)); | |||
assertThat(uuidsIn("projects")) | |||
assertThat(uuidsIn("components")) | |||
.containsOnly(project.uuid(), module2.uuid(), dir1.uuid(), file2.uuid()); | |||
} | |||
@Test | |||
public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_view_from_table_PROJECTS() { | |||
public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_view_from_table_components() { | |||
ComponentDto[] projects = { | |||
db.components().insertPrivateProject(), | |||
db.components().insertPrivateProject(), | |||
@@ -1463,13 +1458,14 @@ public class PurgeDaoTest { | |||
ComponentDto pc3 = db.components().insertComponent(newProjectCopy("c", projects[2], subview2)); | |||
underTest.deleteNonRootComponentsInView(dbSession, singletonList(pc3)); | |||
assertThat(uuidsIn("projects")) | |||
assertThat(uuidsIn("components")) | |||
.containsOnly(view.uuid(), projects[0].uuid(), projects[1].uuid(), projects[2].uuid(), | |||
subview1.uuid(), subview2.uuid(), pc1.uuid(), pc2.uuid()); | |||
underTest.deleteNonRootComponentsInView(dbSession, asList(subview1, pc2)); | |||
assertThat(uuidsIn("projects")) | |||
assertThat(uuidsIn("components")) | |||
.containsOnly(view.uuid(), projects[0].uuid(), projects[1].uuid(), projects[2].uuid(), subview2.uuid(), pc1.uuid()); | |||
assertThat(uuidsIn("projects")).containsOnly(projects[0].uuid(), projects[1].uuid(), projects[2].uuid()); | |||
} | |||
@Test |
@@ -27,6 +27,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.tuple; | |||
@@ -47,9 +48,9 @@ public class ProjectQgateAssociationDaoTest { | |||
ComponentDto project1 = db.components().insertPrivateProject(organization); | |||
ComponentDto project2 = db.components().insertPrivateProject(organization); | |||
ComponentDto project3 = db.components().insertPrivateProject(organization); | |||
db.qualityGates().associateProjectToQualityGate(project1, qualityGate1); | |||
db.qualityGates().associateProjectToQualityGate(project2, qualityGate1); | |||
db.qualityGates().associateProjectToQualityGate(project3, qualityGate2); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate1); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate1); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project3), qualityGate2); | |||
List<ProjectQgateAssociationDto> result = underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder() | |||
.qualityGate(qualityGate1) | |||
@@ -70,8 +71,8 @@ public class ProjectQgateAssociationDaoTest { | |||
ComponentDto project1 = db.components().insertPrivateProject(organization); | |||
ComponentDto project2 = db.components().insertPrivateProject(organization); | |||
ComponentDto project3 = db.components().insertPrivateProject(organization); | |||
db.qualityGates().associateProjectToQualityGate(project1, qualityGate); | |||
db.qualityGates().associateProjectToQualityGate(project2, qualityGate); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate); | |||
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder() | |||
.qualityGate(qualityGate) | |||
@@ -97,8 +98,8 @@ public class ProjectQgateAssociationDaoTest { | |||
ComponentDto project1 = db.components().insertPrivateProject(organization, p -> p.setName("Project One")); | |||
ComponentDto project2 = db.components().insertPrivateProject(organization, p -> p.setName("Project Two")); | |||
ComponentDto project3 = db.components().insertPrivateProject(organization, p -> p.setName("Project Three")); | |||
db.qualityGates().associateProjectToQualityGate(project1, qualityGate); | |||
db.qualityGates().associateProjectToQualityGate(project2, qualityGate); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate); | |||
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder() | |||
.qualityGate(qualityGate) | |||
@@ -138,8 +139,8 @@ public class ProjectQgateAssociationDaoTest { | |||
QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization); | |||
ComponentDto project = db.components().insertPrivateProject(organization); | |||
ComponentDto otherProject = db.components().insertPrivateProject(otherOrganization); | |||
db.qualityGates().associateProjectToQualityGate(project, qualityGate); | |||
db.qualityGates().associateProjectToQualityGate(otherProject, otherQualityGate); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project), qualityGate); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(otherProject), otherQualityGate); | |||
List<ProjectQgateAssociationDto> result = underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder() | |||
.qualityGate(qualityGate) | |||
@@ -154,7 +155,7 @@ public class ProjectQgateAssociationDaoTest { | |||
public void select_qgate_uuid_is_absent() { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
Optional<String> result = underTest.selectQGateUuidByComponentUuid(dbSession, project.uuid()); | |||
Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project.uuid()); | |||
assertThat(result.isPresent()).isFalse(); | |||
} | |||
@@ -166,10 +167,10 @@ public class ProjectQgateAssociationDaoTest { | |||
QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization); | |||
ComponentDto project1 = db.components().insertPrivateProject(organization); | |||
ComponentDto project2 = db.components().insertPrivateProject(organization); | |||
db.qualityGates().associateProjectToQualityGate(project1, qualityGate1); | |||
db.qualityGates().associateProjectToQualityGate(project2, qualityGate2); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate1); | |||
db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate2); | |||
Optional<String> result = underTest.selectQGateUuidByComponentUuid(dbSession, project1.uuid()); | |||
Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project1.uuid()); | |||
assertThat(result).contains(qualityGate1.getUuid()); | |||
} | |||
@@ -178,13 +179,13 @@ public class ProjectQgateAssociationDaoTest { | |||
public void delete_by_project_uuid() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization); | |||
ComponentDto project = db.components().insertPrivateProject(organization); | |||
ProjectDto project = db.components().insertPrivateProjectDto(organization); | |||
db.qualityGates().associateProjectToQualityGate(project, qualityGate); | |||
underTest.deleteByProjectUuid(dbSession, project.uuid()); | |||
underTest.deleteByProjectUuid(dbSession, project.getUuid()); | |||
Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid()); | |||
Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid()); | |||
assertThat(deletedQualityGate).isEmpty(); | |||
} | |||
@@ -193,13 +194,13 @@ public class ProjectQgateAssociationDaoTest { | |||
public void delete_by_qgate_uuid() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization); | |||
ComponentDto project = db.components().insertPrivateProject(organization); | |||
ProjectDto project = db.components().insertPrivateProjectDto(organization); | |||
db.qualityGates().associateProjectToQualityGate(project, qualityGate); | |||
underTest.deleteByQGateUuid(dbSession, qualityGate.getUuid()); | |||
Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid()); | |||
Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid()); | |||
assertThat(deletedQualityGate).isEmpty(); | |||
} | |||
@@ -209,13 +210,13 @@ public class ProjectQgateAssociationDaoTest { | |||
OrganizationDto organization = db.organizations().insert(); | |||
QGateWithOrgDto firstQualityGate = db.qualityGates().insertQualityGate(organization); | |||
QGateWithOrgDto secondQualityGate = db.qualityGates().insertQualityGate(organization); | |||
ComponentDto project = db.components().insertPrivateProject(organization); | |||
ProjectDto project = db.components().insertPrivateProjectDto(organization); | |||
db.qualityGates().associateProjectToQualityGate(project, firstQualityGate); | |||
underTest.updateProjectQGateAssociation(dbSession, project.uuid(), secondQualityGate.getUuid()); | |||
underTest.updateProjectQGateAssociation(dbSession, project.getUuid(), secondQualityGate.getUuid()); | |||
Optional<String> updatedQualityGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid()); | |||
Optional<String> updatedQualityGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid()); | |||
assertThat(updatedQualityGateUuid).contains(secondQualityGate.getUuid()); | |||
} |
@@ -27,8 +27,8 @@ import org.sonar.api.utils.System2; | |||
import org.sonar.core.util.Uuids; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static java.lang.String.format; | |||
import static java.util.Arrays.asList; | |||
@@ -173,7 +173,7 @@ public class QualityGateDaoTest { | |||
public void select_by_project_uuid() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPrivateProject(organization); | |||
ProjectDto project = db.components().insertPrivateProjectDto(organization); | |||
QGateWithOrgDto qualityGate1 = db.qualityGates().insertQualityGate(organization); | |||
QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization); | |||
@@ -183,7 +183,7 @@ public class QualityGateDaoTest { | |||
db.qualityGates().associateProjectToQualityGate(project, qualityGate1); | |||
assertThat(underTest.selectByProjectUuid(dbSession, project.uuid()).getUuid()).isEqualTo(qualityGate1.getUuid()); | |||
assertThat(underTest.selectByProjectUuid(dbSession, project.getUuid()).getUuid()).isEqualTo(qualityGate1.getUuid()); | |||
assertThat(underTest.selectByProjectUuid(dbSession, "not-existing-uuid")).isNull(); | |||
} | |||
@@ -39,6 +39,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import static com.google.common.collect.ImmutableList.of; | |||
@@ -239,9 +240,12 @@ public class QualityProfileDaoTest { | |||
public void test_deleteProjectAssociationsByProfileUuids() { | |||
QProfileDto profile1 = db.qualityProfiles().insert(organization); | |||
QProfileDto profile2 = db.qualityProfiles().insert(organization); | |||
ComponentDto project1 = db.components().insertPrivateProject(organization); | |||
ComponentDto project2 = db.components().insertPrivateProject(organization); | |||
ComponentDto project3 = db.components().insertPrivateProject(organization); | |||
ProjectDto project1 = db.components().insertPrivateProjectDto(organization); | |||
ProjectDto project2 = db.components().insertPrivateProjectDto(organization); | |||
ProjectDto project3 = db.components().insertPrivateProjectDto(organization); | |||
db.getDbClient().projectDao().selectByUuid(dbSession, project1.getUuid()).get(); | |||
db.qualityProfiles().associateWithProject(project1, profile1); | |||
db.qualityProfiles().associateWithProject(project2, profile1); | |||
db.qualityProfiles().associateWithProject(project3, profile2); | |||
@@ -250,14 +254,14 @@ public class QualityProfileDaoTest { | |||
List<Map<String, Object>> rows = db.select(dbSession, "select project_uuid as \"projectUuid\", profile_key as \"profileKey\" from project_qprofiles"); | |||
assertThat(rows).hasSize(1); | |||
assertThat(rows.get(0).get("projectUuid")).isEqualTo(project3.uuid()); | |||
assertThat(rows.get(0).get("projectUuid")).isEqualTo(project3.getUuid()); | |||
assertThat(rows.get(0).get("profileKey")).isEqualTo(profile2.getKee()); | |||
} | |||
@Test | |||
public void deleteProjectAssociationsByProfileUuids_does_nothing_if_empty_uuids() { | |||
QProfileDto profile = db.qualityProfiles().insert(organization); | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
ProjectDto project = db.components().insertPrivateProjectDto(); | |||
db.qualityProfiles().associateWithProject(project, profile); | |||
underTest.deleteProjectAssociationsByProfileUuids(dbSession, Collections.emptyList()); | |||
@@ -562,7 +566,6 @@ public class QualityProfileDaoTest { | |||
.isNull(); | |||
} | |||
@Test | |||
public void selectDefaultBuiltInProfilesWithoutActiveRules() { | |||
// a quality profile without active rules but not builtin | |||
@@ -651,15 +654,15 @@ public class QualityProfileDaoTest { | |||
public void countProjectsByProfileKey() { | |||
QProfileDto profileWithoutProjects = db.qualityProfiles().insert(organization); | |||
QProfileDto profileWithProjects = db.qualityProfiles().insert(organization); | |||
ComponentDto project1 = db.components().insertPrivateProject(organization); | |||
ComponentDto project2 = db.components().insertPrivateProject(organization); | |||
ProjectDto project1 = db.components().insertPrivateProjectDto(organization); | |||
ProjectDto project2 = db.components().insertPrivateProjectDto(organization); | |||
db.qualityProfiles().associateWithProject(project1, profileWithProjects); | |||
db.qualityProfiles().associateWithProject(project2, profileWithProjects); | |||
OrganizationDto otherOrg = db.organizations().insert(); | |||
QProfileDto profileInOtherOrg = db.qualityProfiles().insert(otherOrg); | |||
ComponentDto projectInOtherOrg = db.components().insertPrivateProject(otherOrg); | |||
ProjectDto projectInOtherOrg = db.components().insertPrivateProjectDto(otherOrg); | |||
db.qualityProfiles().associateWithProject(projectInOtherOrg, profileInOtherOrg); | |||
assertThat(underTest.countProjectsByOrganizationAndProfiles(dbSession, organization, asList(profileWithoutProjects, profileWithProjects, profileInOtherOrg))).containsOnly( | |||
@@ -671,8 +674,8 @@ public class QualityProfileDaoTest { | |||
@Test | |||
public void test_selectAssociatedToProjectAndLanguage() { | |||
OrganizationDto org = db.organizations().insert(); | |||
ComponentDto project1 = db.components().insertPublicProject(org); | |||
ComponentDto project2 = db.components().insertPublicProject(org); | |||
ProjectDto project1 = db.components().insertPublicProjectDto(org); | |||
ProjectDto project2 = db.components().insertPublicProjectDto(org); | |||
QProfileDto javaProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("java")); | |||
QProfileDto jsProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("js")); | |||
db.qualityProfiles().associateWithProject(project1, javaProfile, jsProfile); | |||
@@ -690,8 +693,8 @@ public class QualityProfileDaoTest { | |||
@Test | |||
public void test_selectAssociatedToProjectUuidAndLanguages() { | |||
OrganizationDto org = db.organizations().insert(); | |||
ComponentDto project1 = db.components().insertPublicProject(org); | |||
ComponentDto project2 = db.components().insertPublicProject(org); | |||
ProjectDto project1 = db.components().insertPublicProjectDto(org); | |||
ProjectDto project2 = db.components().insertPublicProjectDto(org); | |||
QProfileDto javaProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("java")); | |||
QProfileDto jsProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("js")); | |||
db.qualityProfiles().associateWithProject(project1, javaProfile, jsProfile); | |||
@@ -713,7 +716,7 @@ public class QualityProfileDaoTest { | |||
@Test | |||
public void test_updateProjectProfileAssociation() { | |||
OrganizationDto org = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPrivateProject(org); | |||
ProjectDto project = db.components().insertPrivateProjectDto(org); | |||
QProfileDto javaProfile1 = db.qualityProfiles().insert(org, p -> p.setLanguage("java")); | |||
QProfileDto jsProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("js")); | |||
QProfileDto javaProfile2 = db.qualityProfiles().insert(org, p -> p.setLanguage("java")); | |||
@@ -749,12 +752,12 @@ public class QualityProfileDaoTest { | |||
QProfileDto profile1 = newQualityProfileDto(); | |||
db.qualityProfiles().insert(profile1); | |||
db.qualityProfiles().associateWithProject(project1, profile1); | |||
db.qualityProfiles().associateWithProject(project2, profile1); | |||
db.qualityProfiles().associateWithProject(db.components().getProjectDto(project1), profile1); | |||
db.qualityProfiles().associateWithProject(db.components().getProjectDto(project2), profile1); | |||
QProfileDto profile2 = newQualityProfileDto(); | |||
db.qualityProfiles().insert(profile2); | |||
db.qualityProfiles().associateWithProject(project3, profile2); | |||
db.qualityProfiles().associateWithProject(db.components().getProjectDto(project3), profile2); | |||
QProfileDto profile3 = newQualityProfileDto(); | |||
assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, null)) | |||
@@ -778,11 +781,11 @@ public class QualityProfileDaoTest { | |||
QProfileDto profile1 = newQualityProfileDto(); | |||
db.qualityProfiles().insert(profile1); | |||
db.qualityProfiles().associateWithProject(project1, profile1); | |||
db.qualityProfiles().associateWithProject(db.components().getProjectDto(project1), profile1); | |||
QProfileDto profile2 = newQualityProfileDto(); | |||
db.qualityProfiles().insert(profile2); | |||
db.qualityProfiles().associateWithProject(project2, profile2); | |||
db.qualityProfiles().associateWithProject(db.components().getProjectDto(project2), profile2); | |||
QProfileDto profile3 = newQualityProfileDto(); | |||
assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, null)) | |||
@@ -806,11 +809,11 @@ public class QualityProfileDaoTest { | |||
QProfileDto profile1 = newQualityProfileDto(); | |||
db.qualityProfiles().insert(profile1); | |||
db.qualityProfiles().associateWithProject(project1, profile1); | |||
db.qualityProfiles().associateWithProject(db.components().getProjectDto(project1), profile1); | |||
QProfileDto profile2 = newQualityProfileDto(); | |||
db.qualityProfiles().insert(profile2); | |||
db.qualityProfiles().associateWithProject(project2, profile2); | |||
db.qualityProfiles().associateWithProject(db.components().getProjectDto(project2), profile2); | |||
QProfileDto profile3 = newQualityProfileDto(); | |||
assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, null)) |
@@ -36,6 +36,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.emptyList; | |||
@@ -520,7 +521,7 @@ public class UserDaoTest { | |||
session.commit(); | |||
underTest.cleanHomepage(session, new ComponentDto().setUuid("dummy-project-UUID")); | |||
underTest.cleanHomepage(session, new ProjectDto().setUuid("dummy-project-UUID")); | |||
UserDto userWithAHomepageReloaded = underTest.selectUserById(session, userUnderTest.getId()); | |||
assertThat(userWithAHomepageReloaded.getUpdatedAt()).isEqualTo(NOW); |
@@ -29,9 +29,9 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDbTester; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -149,15 +149,15 @@ public class WebhookDaoTest { | |||
@Test | |||
public void cleanWebhooksOfAProject() { | |||
OrganizationDto organization = organizationDbTester.insert(); | |||
ComponentDto componentDto = componentDbTester.insertPrivateProject(organization); | |||
webhookDbTester.insertWebhook(componentDto); | |||
webhookDbTester.insertWebhook(componentDto); | |||
webhookDbTester.insertWebhook(componentDto); | |||
webhookDbTester.insertWebhook(componentDto); | |||
ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(organization); | |||
webhookDbTester.insertWebhook(projectDto); | |||
webhookDbTester.insertWebhook(projectDto); | |||
webhookDbTester.insertWebhook(projectDto); | |||
webhookDbTester.insertWebhook(projectDto); | |||
underTest.deleteByProject(dbSession, componentDto); | |||
underTest.deleteByProject(dbSession, projectDto); | |||
Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, componentDto.uuid()); | |||
Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, projectDto.getUuid()); | |||
assertThat(reloaded).isEmpty(); | |||
} | |||
@@ -23,7 +23,7 @@ import java.util.function.Consumer; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.alm.setting.AlmSettingDto; | |||
import org.sonar.db.alm.setting.ProjectAlmSettingDto; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static java.util.Arrays.stream; | |||
import static org.sonar.db.almsettings.AlmSettingsTesting.newAzureAlmSettingDto; | |||
@@ -64,20 +64,20 @@ public class AlmSettingsDbTester { | |||
} | |||
@SafeVarargs | |||
public final ProjectAlmSettingDto insertGitHubProjectAlmSetting(AlmSettingDto githubAlmSetting, ComponentDto project, Consumer<ProjectAlmSettingDto>... populators) { | |||
public final ProjectAlmSettingDto insertGitHubProjectAlmSetting(AlmSettingDto githubAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) { | |||
return insertProjectAlmSetting(newGithubProjectAlmSettingDto(githubAlmSetting, project), populators); | |||
} | |||
public ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ComponentDto project) { | |||
public ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project) { | |||
return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project)); | |||
} | |||
public ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ComponentDto project) { | |||
public ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ProjectDto project) { | |||
return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project)); | |||
} | |||
@SafeVarargs | |||
public final ProjectAlmSettingDto insertBitbucketProjectAlmSetting(AlmSettingDto bitbucketAlmSetting, ComponentDto project, Consumer<ProjectAlmSettingDto>... populators) { | |||
public final ProjectAlmSettingDto insertBitbucketProjectAlmSetting(AlmSettingDto bitbucketAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) { | |||
return insertProjectAlmSetting(newBitbucketProjectAlmSettingDto(bitbucketAlmSetting, project), populators); | |||
} | |||
@@ -22,7 +22,7 @@ package org.sonar.db.almsettings; | |||
import org.sonar.db.alm.setting.ALM; | |||
import org.sonar.db.alm.setting.AlmSettingDto; | |||
import org.sonar.db.alm.setting.ProjectAlmSettingDto; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
@@ -59,29 +59,29 @@ public class AlmSettingsTesting { | |||
.setAlm(ALM.BITBUCKET); | |||
} | |||
public static ProjectAlmSettingDto newGithubProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ComponentDto project) { | |||
public static ProjectAlmSettingDto newGithubProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ProjectDto project) { | |||
return new ProjectAlmSettingDto() | |||
.setAlmSettingUuid(githubAlmSetting.getUuid()) | |||
.setProjectUuid(project.uuid()) | |||
.setProjectUuid(project.getUuid()) | |||
.setAlmRepo(randomAlphanumeric(256)); | |||
} | |||
static ProjectAlmSettingDto newAzureProjectAlmSettingDto(AlmSettingDto azureAlmSetting, ComponentDto project) { | |||
static ProjectAlmSettingDto newGitlabProjectAlmSettingDto(AlmSettingDto gitlabAlmSetting, ProjectDto project) { | |||
return new ProjectAlmSettingDto() | |||
.setAlmSettingUuid(azureAlmSetting.getUuid()) | |||
.setProjectUuid(project.uuid()); | |||
.setAlmSettingUuid(gitlabAlmSetting.getUuid()) | |||
.setProjectUuid(project.getUuid()); | |||
} | |||
static ProjectAlmSettingDto newGitlabProjectAlmSettingDto(AlmSettingDto gitlabAlmSetting, ComponentDto project) { | |||
static ProjectAlmSettingDto newAzureProjectAlmSettingDto(AlmSettingDto azureAlmSetting, ProjectDto project) { | |||
return new ProjectAlmSettingDto() | |||
.setAlmSettingUuid(gitlabAlmSetting.getUuid()) | |||
.setProjectUuid(project.uuid()); | |||
.setAlmSettingUuid(azureAlmSetting.getUuid()) | |||
.setProjectUuid(project.getUuid()); | |||
} | |||
public static ProjectAlmSettingDto newBitbucketProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ComponentDto project) { | |||
public static ProjectAlmSettingDto newBitbucketProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ProjectDto project) { | |||
return new ProjectAlmSettingDto() | |||
.setAlmSettingUuid(githubAlmSetting.getUuid()) | |||
.setProjectUuid(project.uuid()) | |||
.setProjectUuid(project.getUuid()) | |||
.setAlmRepo(randomAlphanumeric(256)) | |||
.setAlmSlug(randomAlphanumeric(256)); | |||
} |
@@ -22,10 +22,13 @@ package org.sonar.db.component; | |||
import java.util.Arrays; | |||
import java.util.function.Consumer; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.resources.Qualifiers; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static com.google.common.base.Preconditions.checkState; | |||
@@ -44,19 +47,13 @@ public class ComponentDbTester { | |||
} | |||
public SnapshotDto insertProjectAndSnapshot(ComponentDto component) { | |||
return insertComponentAndSnapshot(component); | |||
insertComponentAndBranchAndProject(component, null, noExtraConfiguration()); | |||
return insertSnapshot(component); | |||
} | |||
public SnapshotDto insertViewAndSnapshot(ComponentDto component) { | |||
return insertComponentAndSnapshot(component); | |||
} | |||
private SnapshotDto insertComponentAndSnapshot(ComponentDto component) { | |||
dbClient.componentDao().insert(dbSession, component); | |||
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, SnapshotTesting.newAnalysis(component)); | |||
db.commit(); | |||
return snapshot; | |||
return insertSnapshot(component); | |||
} | |||
public ComponentDto insertComponent(ComponentDto component) { | |||
@@ -64,52 +61,107 @@ public class ComponentDbTester { | |||
} | |||
public ComponentDto insertPrivateProject() { | |||
return insertComponentImpl(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, noExtraConfiguration()); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, noExtraConfiguration()); | |||
} | |||
public ProjectDto getProjectDto(ComponentDto project) { | |||
return db.getDbClient().projectDao().selectByUuid(dbSession, project.uuid()).get(); | |||
} | |||
public ComponentDto insertPrivateProject(ComponentDto componentDto) { | |||
return insertComponentAndBranchAndProject(componentDto, true, noExtraConfiguration()); | |||
} | |||
public ComponentDto insertPublicProject() { | |||
return insertComponentImpl(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, noExtraConfiguration()); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, noExtraConfiguration()); | |||
} | |||
public ComponentDto insertPublicProject(ComponentDto componentDto) { | |||
return insertComponentAndBranchAndProject(componentDto, false, noExtraConfiguration()); | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertPrivateProject(Consumer<ComponentDto>... dtoPopulators) { | |||
return insertComponentImpl(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, dtoPopulators); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, null, dtoPopulators); | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertPublicProject(Consumer<ComponentDto>... dtoPopulators) { | |||
return insertComponentImpl(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, dtoPopulators); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, null, dtoPopulators); | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) { | |||
return insertComponentImpl(ComponentTesting.newPrivateProjectDto(organizationDto), true, dtoPopulators); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, null, dtoPopulators); | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) { | |||
return insertComponentImpl(ComponentTesting.newPublicProjectDto(organizationDto), false, dtoPopulators); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false, null, dtoPopulators); | |||
} | |||
public ComponentDto insertPrivateProject(OrganizationDto organizationDto) { | |||
return insertComponentImpl(ComponentTesting.newPrivateProjectDto(organizationDto), true, noExtraConfiguration()); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, noExtraConfiguration()); | |||
} | |||
public ComponentDto insertPublicProject(OrganizationDto organizationDto) { | |||
return insertComponentImpl(ComponentTesting.newPublicProjectDto(organizationDto), false, noExtraConfiguration()); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false, noExtraConfiguration()); | |||
} | |||
public ProjectDto insertPublicProjectDto() { | |||
ComponentDto componentDto = insertPublicProject(); | |||
return getProjectDto(componentDto); | |||
} | |||
public ProjectDto insertPrivateProjectDto() { | |||
ComponentDto componentDto = insertPrivateProject(); | |||
return getProjectDto(componentDto); | |||
} | |||
public ProjectDto insertPublicProjectDto(OrganizationDto organization) { | |||
ComponentDto componentDto = insertPublicProject(organization); | |||
return getProjectDto(componentDto); | |||
} | |||
@SafeVarargs | |||
public final ProjectDto insertPublicProjectDto(OrganizationDto organization, Consumer<ComponentDto>... dtoPopulators) { | |||
ComponentDto componentDto = insertPublicProject(organization, dtoPopulators); | |||
return getProjectDto(componentDto); | |||
} | |||
public ProjectDto insertPrivateProjectDto(OrganizationDto organization) { | |||
ComponentDto componentDto = insertPrivateProject(organization); | |||
return getProjectDto(componentDto); | |||
} | |||
@SafeVarargs | |||
public final ProjectDto insertPrivateProjectDto(Consumer<ComponentDto>... dtoPopulators) { | |||
ComponentDto componentDto = insertPrivateProject(dtoPopulators); | |||
return getProjectDto(componentDto); | |||
} | |||
public ProjectDto insertPrivateProjectDto(OrganizationDto organization, Consumer<BranchDto> branchConsumer) { | |||
ComponentDto componentDto = insertPrivateProjectWithCustomBranch(organization, branchConsumer); | |||
return getProjectDto(componentDto); | |||
} | |||
public ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid) { | |||
return insertComponentImpl(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, noExtraConfiguration()); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, noExtraConfiguration()); | |||
} | |||
public ComponentDto insertPublicProject(OrganizationDto organizationDto, String uuid) { | |||
return insertComponentImpl(ComponentTesting.newPublicProjectDto(organizationDto, uuid), false, noExtraConfiguration()); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto, uuid), false, noExtraConfiguration()); | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid, Consumer<ComponentDto>... dtoPopulators) { | |||
return insertComponentImpl(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, dtoPopulators); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, null, dtoPopulators); | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertPrivateProjectWithCustomBranch(OrganizationDto organizationDto, Consumer<BranchDto> branchPopulator, | |||
Consumer<ComponentDto>... componentPopulator) { | |||
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, branchPopulator, componentPopulator); | |||
} | |||
/** | |||
@@ -183,7 +235,8 @@ public class ComponentDbTester { | |||
@SafeVarargs | |||
public final ComponentDto insertPublicApplication(OrganizationDto organization, Consumer<ComponentDto>... dtoPopulators) { | |||
return insertComponentImpl(ComponentTesting.newApplication(organization).setPrivate(false), false, dtoPopulators); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(false), false, b -> { | |||
}, dtoPopulators); | |||
} | |||
@SafeVarargs | |||
@@ -193,7 +246,8 @@ public class ComponentDbTester { | |||
@SafeVarargs | |||
public final ComponentDto insertPrivateApplication(OrganizationDto organization, Consumer<ComponentDto>... dtoPopulators) { | |||
return insertComponentImpl(ComponentTesting.newApplication(organization).setPrivate(true), true, dtoPopulators); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(true), true, b -> { | |||
}, dtoPopulators); | |||
} | |||
/** | |||
@@ -202,12 +256,13 @@ public class ComponentDbTester { | |||
*/ | |||
@SafeVarargs | |||
public final ComponentDto insertApplication(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) { | |||
return insertComponentImpl(ComponentTesting.newApplication(organizationDto), false, dtoPopulators); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organizationDto), false, b -> { | |||
}, dtoPopulators); | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertSubView(ComponentDto view, Consumer<ComponentDto>... dtoPopulators) { | |||
return insertComponentImpl(ComponentTesting.newSubView(view), view.isPrivate(), dtoPopulators); | |||
return insertComponentAndBranchAndProject(ComponentTesting.newSubView(view), view.isPrivate(), null, dtoPopulators); | |||
} | |||
private static <T> Consumer<T> noExtraConfiguration() { | |||
@@ -215,10 +270,29 @@ public class ComponentDbTester { | |||
}; | |||
} | |||
@SafeVarargs | |||
private final ComponentDto insertComponentAndBranchAndProject(ComponentDto component, @Nullable Boolean isPrivate, @Nullable Consumer<BranchDto> branchPopulator, | |||
Consumer<ComponentDto>... dtoPopulators) { | |||
insertComponentImpl(component, isPrivate, dtoPopulators); | |||
ProjectDto projectDto = toProjectDto(component, System2.INSTANCE.now()); | |||
dbClient.projectDao().insert(dbSession, projectDto); | |||
BranchDto branchDto = ComponentTesting.newBranchDto(component, BRANCH); | |||
branchDto.setExcludeFromPurge(true); | |||
if (branchPopulator != null) { | |||
branchPopulator.accept(branchDto); | |||
} | |||
dbClient.branchDao().insert(dbSession, branchDto); | |||
db.commit(); | |||
return component; | |||
} | |||
@SafeVarargs | |||
private final ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate, Consumer<ComponentDto>... dtoPopulators) { | |||
Arrays.stream(dtoPopulators) | |||
.forEach(dtoPopulator -> dtoPopulator.accept(component)); | |||
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(component)); | |||
checkState(isPrivate == null || component.isPrivate() == isPrivate, "Illegal modification of private flag"); | |||
dbClient.componentDao().insert(dbSession, component); | |||
db.commit(); | |||
@@ -244,9 +318,17 @@ public class ComponentDbTester { | |||
public SnapshotDto insertSnapshot(ComponentDto componentDto, Consumer<SnapshotDto> consumer) { | |||
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(componentDto); | |||
consumer.accept(snapshotDto); | |||
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, snapshotDto); | |||
db.commit(); | |||
return snapshot; | |||
return insertSnapshot(snapshotDto); | |||
} | |||
public SnapshotDto insertSnapshot(BranchDto branchDto) { | |||
return insertSnapshot(branchDto, noExtraConfiguration()); | |||
} | |||
public SnapshotDto insertSnapshot(BranchDto branchDto, Consumer<SnapshotDto> consumer) { | |||
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(branchDto); | |||
consumer.accept(snapshotDto); | |||
return insertSnapshot(snapshotDto); | |||
} | |||
public void insertSnapshots(SnapshotDto... snapshotDtos) { | |||
@@ -255,59 +337,40 @@ public class ComponentDbTester { | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertMainBranch(Consumer<ComponentDto>... dtoPopulators) { | |||
return insertMainBranch(db.getDefaultOrganization(), dtoPopulators); | |||
public final ComponentDto insertProjectBranch(ComponentDto project, Consumer<BranchDto>... dtoPopulators) { | |||
// MainBranchProjectUuid will be null if it's a main branch | |||
BranchDto branchDto = ComponentTesting.newBranchDto(firstNonNull(project.getMainBranchProjectUuid(), project.projectUuid()), BRANCH); | |||
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(branchDto)); | |||
return insertProjectBranch(project, branchDto); | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertMainBranch(OrganizationDto organization, Consumer<ComponentDto>... dtoPopulators) { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(organization); | |||
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(project)); | |||
return insertMainBranch(project); | |||
} | |||
public final ComponentDto insertMainBranch(ComponentDto project) { | |||
BranchDto branchDto = ComponentTesting.newBranchDto(project, BRANCH); | |||
branchDto.setExcludeFromPurge(true); | |||
insertComponent(project); | |||
dbClient.branchDao().insert(dbSession, branchDto); | |||
db.commit(); | |||
return project; | |||
public final BranchDto insertProjectBranch(ProjectDto project, Consumer<BranchDto>... dtoPopulators) { | |||
BranchDto branchDto = ComponentTesting.newBranchDto(project.getUuid(), BRANCH); | |||
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(branchDto)); | |||
insertProjectBranch(project, branchDto); | |||
return branchDto; | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertMainBranch(OrganizationDto organization, String mainBranchName, Consumer<ComponentDto>... dtoPopulators) { | |||
public final ComponentDto insertProjectBranch(OrganizationDto organization, Consumer<BranchDto>... dtoPopulators) { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(organization); | |||
BranchDto branchDto = ComponentTesting.newBranchDto(project, BRANCH).setKey(mainBranchName); | |||
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(project)); | |||
insertComponent(project); | |||
dbClient.branchDao().insert(dbSession, branchDto); | |||
db.commit(); | |||
return project; | |||
return insertProjectBranch(project, dtoPopulators); | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertProjectBranch(ComponentDto project, Consumer<BranchDto>... dtoPopulators) { | |||
// MainBranchProjectUuid will be null if it's a main branch | |||
BranchDto branchDto = ComponentTesting.newBranchDto(firstNonNull(project.getMainBranchProjectUuid(), project.projectUuid()), BRANCH); | |||
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(branchDto)); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, branchDto); | |||
public final ComponentDto insertProjectBranch(ProjectDto project, BranchDto branchDto) { | |||
checkArgument(branchDto.getProjectUuid().equals(project.getUuid())); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto); | |||
insertComponent(branch); | |||
dbClient.branchDao().insert(dbSession, branchDto); | |||
db.commit(); | |||
return branch; | |||
} | |||
@SafeVarargs | |||
public final ComponentDto insertProjectBranch(OrganizationDto organization, Consumer<BranchDto>... dtoPopulators) { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(organization); | |||
return insertProjectBranch(project, dtoPopulators); | |||
} | |||
public final ComponentDto insertProjectBranch(ComponentDto project, BranchDto branchDto) { | |||
// MainBranchProjectUuid will be null if it's a main branch | |||
checkArgument(branchDto.getProjectUuid().equals(firstNonNull(project.getMainBranchProjectUuid(), project.projectUuid()))); | |||
ComponentDto branch = ComponentTesting.newProjectBranch(project, branchDto); | |||
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto); | |||
insertComponent(branch); | |||
dbClient.branchDao().insert(dbSession, branchDto); | |||
db.commit(); | |||
@@ -318,4 +381,19 @@ public class ComponentDbTester { | |||
return (first != null) ? first : second; | |||
} | |||
// TODO temporary constructor to quickly create project from previous project component. | |||
private ProjectDto toProjectDto(ComponentDto componentDto, long createTime) { | |||
return new ProjectDto() | |||
.setUuid(componentDto.uuid()) | |||
.setKey(componentDto.getDbKey()) | |||
.setQualifier(componentDto.qualifier() != null ? componentDto.qualifier() : Qualifiers.PROJECT) | |||
.setCreatedAt(createTime) | |||
.setUpdatedAt(createTime) | |||
.setPrivate(componentDto.isPrivate()) | |||
.setDescription(componentDto.description()) | |||
.setName(componentDto.name()) | |||
.setOrganizationUuid(componentDto.getOrganizationUuid()) | |||
.setTags(componentDto.getTags()) | |||
.setTagsString(componentDto.getTagsString()); | |||
} | |||
} |
@@ -25,6 +25,7 @@ import org.sonar.api.resources.Qualifiers; | |||
import org.sonar.api.resources.Scopes; | |||
import org.sonar.core.util.Uuids; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static com.google.common.base.Preconditions.checkNotNull; | |||
@@ -126,6 +127,10 @@ public class ComponentTesting { | |||
return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), true); | |||
} | |||
public static ProjectDto createPrivateProjectDto(OrganizationDto organizationDto) { | |||
return createProjectDto(organizationDto.getUuid(), Uuids.createFast(), true); | |||
} | |||
public static ComponentDto newPrivateProjectDto(OrganizationDto organizationDto, String uuid) { | |||
return newProjectDto(organizationDto.getUuid(), uuid, true); | |||
} | |||
@@ -138,6 +143,17 @@ public class ComponentTesting { | |||
return newProjectDto(organizationDto.getUuid(), uuid, false); | |||
} | |||
private static ProjectDto createProjectDto(String organizationUuid, String uuid, boolean isPrivate) { | |||
return new ProjectDto() | |||
.setOrganizationUuid(organizationUuid) | |||
.setUuid(uuid) | |||
.setKey("KEY_" + uuid) | |||
.setQualifier(Qualifiers.PROJECT) | |||
.setName("NAME_" + uuid) | |||
.setDescription("DESCRIPTION_" + uuid) | |||
.setPrivate(isPrivate); | |||
} | |||
private static ComponentDto newProjectDto(String organizationUuid, String uuid, boolean isPrivate) { | |||
return new ComponentDto() | |||
.setId(nextLong()) | |||
@@ -248,7 +264,33 @@ public class ComponentTesting { | |||
.setBranchType(branchType); | |||
} | |||
public static ComponentDto newProjectBranch(ComponentDto project, BranchDto branchDto) { | |||
public static ComponentDto newBranchComponent(ProjectDto project, BranchDto branchDto) { | |||
String branchName = branchDto.getKey(); | |||
String branchSeparator = branchDto.getBranchType() == PULL_REQUEST ? PULL_REQUEST_SEPARATOR : BRANCH_KEY_SEPARATOR; | |||
String uuid = branchDto.getUuid(); | |||
return new ComponentDto() | |||
.setUuid(uuid) | |||
.setOrganizationUuid(project.getOrganizationUuid()) | |||
.setUuidPath(UUID_PATH_OF_ROOT) | |||
.setProjectUuid(uuid) | |||
.setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) | |||
.setRootUuid(uuid) | |||
// name of the branch is not mandatory on the main branch | |||
.setDbKey(branchName != null ? project.getKey() + branchSeparator + branchName : project.getKey()) | |||
.setMainBranchProjectUuid(project.getUuid()) | |||
.setName(project.getName()) | |||
.setLongName(project.getName()) | |||
.setDescription(project.getDescription()) | |||
.setScope(Scopes.PROJECT) | |||
.setQualifier(Qualifiers.PROJECT) | |||
.setPath(null) | |||
.setLanguage(null) | |||
.setEnabled(true) | |||
.setPrivate(project.isPrivate()); | |||
} | |||
public static ComponentDto newBranchComponent(ComponentDto project, BranchDto branchDto) { | |||
checkArgument(project.qualifier().equals(Qualifiers.PROJECT) || project.qualifier().equals(Qualifiers.APP)); | |||
checkArgument(project.getMainBranchProjectUuid() == null); | |||
String branchName = branchDto.getKey(); |
@@ -29,9 +29,18 @@ public class SnapshotTesting { | |||
public static SnapshotDto newAnalysis(ComponentDto rootComponent) { | |||
checkNotNull(rootComponent.uuid(), "Project UUID must be set"); | |||
checkArgument(rootComponent.uuid().equals(rootComponent.projectUuid()), "Component is not a tree root"); | |||
return newAnalysis(rootComponent.uuid()); | |||
} | |||
public static SnapshotDto newAnalysis(BranchDto branchDto) { | |||
checkNotNull(branchDto.getUuid(), "Project UUID must be set"); | |||
return newAnalysis(branchDto.getUuid()); | |||
} | |||
public static SnapshotDto newAnalysis(String uuid) { | |||
return new SnapshotDto() | |||
.setUuid(randomAlphanumeric(40)) | |||
.setComponentUuid(rootComponent.uuid()) | |||
.setComponentUuid(uuid) | |||
.setStatus(SnapshotDto.STATUS_PROCESSED) | |||
.setCreatedAt(System.currentTimeMillis()) | |||
.setBuildDate(System.currentTimeMillis()) |
@@ -30,6 +30,7 @@ import org.sonar.core.issue.FieldDiffs; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.db.user.UserDto; | |||
@@ -66,7 +67,7 @@ public class IssueDbTester { | |||
@SafeVarargs | |||
public final IssueDto insert(OrganizationDto organizationDto, Consumer<IssueDto>... populators) { | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
ComponentDto project = db.components().insertMainBranch(organizationDto); | |||
ComponentDto project = db.components().insertPublicProject(organizationDto); | |||
ComponentDto file = db.components().insertComponent(newFileDto(project)); | |||
IssueDto issue = newIssue(rule, project, file); | |||
stream(populators).forEach(p -> p.accept(issue)); | |||
@@ -98,6 +99,13 @@ public class IssueDbTester { | |||
return insertIssue(issue); | |||
} | |||
@SafeVarargs | |||
public final IssueDto insert(RuleDefinitionDto rule, ProjectDto project, ComponentDto file, Consumer<IssueDto>... populators) { | |||
IssueDto issue = newIssue(rule, project, file); | |||
stream(populators).forEach(p -> p.accept(issue)); | |||
return insert(issue); | |||
} | |||
/** | |||
* Inserts an issue. | |||
* | |||
@@ -126,7 +134,7 @@ public class IssueDbTester { | |||
@SafeVarargs | |||
public final IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto>... populators) { | |||
RuleDefinitionDto rule = db.rules().insertIssueRule(); | |||
ComponentDto project = db.components().insertMainBranch(organizationDto); | |||
ComponentDto project = db.components().insertPrivateProject(organizationDto); | |||
ComponentDto file = db.components().insertComponent(newFileDto(project)); | |||
IssueDto issue = newIssue(rule, project, file) | |||
.setType(RULE_TYPES_EXCEPT_HOTSPOTS[new Random().nextInt(RULE_TYPES_EXCEPT_HOTSPOTS.length)]); | |||
@@ -191,7 +199,7 @@ public class IssueDbTester { | |||
@SafeVarargs | |||
public final IssueDto insertHotspot(OrganizationDto organizationDto, Consumer<IssueDto>... populators) { | |||
RuleDefinitionDto rule = db.rules().insertHotspotRule(); | |||
ComponentDto project = db.components().insertMainBranch(organizationDto); | |||
ComponentDto project = db.components().insertPrivateProject(organizationDto); | |||
ComponentDto file = db.components().insertComponent(newFileDto(project)); | |||
IssueDto issue = newIssue(rule, project, file) | |||
.setType(SECURITY_HOTSPOT) |
@@ -27,9 +27,9 @@ 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.component.ComponentDto; | |||
import org.sonar.db.metric.MetricDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.apache.commons.lang.RandomStringUtils.randomNumeric; | |||
@@ -69,8 +69,8 @@ public class QualityGateDbTester { | |||
return dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid()); | |||
} | |||
public void associateProjectToQualityGate(ComponentDto component, QualityGateDto qualityGate) { | |||
dbClient.projectQgateAssociationDao().insertProjectQGateAssociation(dbSession, component.uuid(), qualityGate.getUuid()); | |||
public void associateProjectToQualityGate(ProjectDto project, QualityGateDto qualityGate) { | |||
dbClient.projectQgateAssociationDao().insertProjectQGateAssociation(dbSession, project.getUuid(), qualityGate.getUuid()); | |||
db.commit(); | |||
} | |||
@@ -104,6 +104,6 @@ public class QualityGateDbTester { | |||
} | |||
public Optional<String> selectQGateUuidByComponentUuid(String componentUuid) { | |||
return dbClient.projectQgateAssociationDao().selectQGateUuidByComponentUuid(dbSession, componentUuid); | |||
return dbClient.projectQgateAssociationDao().selectQGateUuidByProjectUuid(dbSession, componentUuid); | |||
} | |||
} |
@@ -27,8 +27,8 @@ 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.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.db.user.GroupDto; | |||
import org.sonar.db.user.UserDto; | |||
@@ -79,7 +79,7 @@ public class QualityProfileDbTester { | |||
return this; | |||
} | |||
public QualityProfileDbTester associateWithProject(ComponentDto project, QProfileDto profile, QProfileDto... otherProfiles) { | |||
public QualityProfileDbTester associateWithProject(ProjectDto project, QProfileDto profile, QProfileDto... otherProfiles) { | |||
dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, profile); | |||
for (QProfileDto p : otherProfiles) { | |||
dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, p); |
@@ -36,6 +36,7 @@ import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.permission.GroupPermissionDto; | |||
import org.sonar.db.permission.OrganizationPermission; | |||
import org.sonar.db.permission.UserPermissionDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static java.lang.String.format; |
@@ -24,6 +24,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.sonar.db.webhook.WebhookTesting.newWebhook; | |||
@@ -39,7 +40,7 @@ public class WebhookDbTester { | |||
return insert(newWebhook(organizationDto)); | |||
} | |||
public WebhookDto insertWebhook(ComponentDto project) { | |||
public WebhookDto insertWebhook(ProjectDto project) { | |||
return insert(newWebhook(project)); | |||
} | |||
@@ -20,11 +20,10 @@ | |||
package org.sonar.db.webhook; | |||
import java.util.Arrays; | |||
import java.util.Calendar; | |||
import java.util.function.Consumer; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import java.util.Calendar; | |||
import org.sonar.db.project.ProjectDto; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
@@ -34,9 +33,9 @@ public class WebhookTesting { | |||
// only statics | |||
} | |||
public static WebhookDto newWebhook(ComponentDto project) { | |||
public static WebhookDto newWebhook(ProjectDto project) { | |||
return getWebhookDto() | |||
.setProjectUuid(project.uuid()); | |||
.setProjectUuid(project.getUuid()); | |||
} | |||
public static WebhookDto newProjectWebhook(String projectUuid) { | |||
@@ -52,8 +51,8 @@ public class WebhookTesting { | |||
@SafeVarargs | |||
public static WebhookDto newOrganizationWebhook(String name, String organizationUuid, Consumer<WebhookDto>... consumers) { | |||
return getWebhookDto(consumers) | |||
.setName(name) | |||
.setOrganizationUuid(organizationUuid); | |||
.setName(name) | |||
.setOrganizationUuid(organizationUuid); | |||
} | |||
@SafeVarargs |
@@ -0,0 +1,129 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v81; | |||
import java.sql.Connection; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.db.DatabaseUtils; | |||
import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef; | |||
import org.sonar.server.platform.db.migration.def.BooleanColumnDef; | |||
import org.sonar.server.platform.db.migration.def.VarcharColumnDef; | |||
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; | |||
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder; | |||
import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder; | |||
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 CreateProjectsTable extends DdlChange { | |||
private static final String TABLE_NAME = "projects"; | |||
private static final VarcharColumnDef UUID_COLUMN = newVarcharColumnDefBuilder() | |||
.setColumnName("uuid") | |||
.setIsNullable(false) | |||
.setLimit(UUID_SIZE) | |||
.build(); | |||
private static final VarcharColumnDef KEE_COLUMN = newVarcharColumnDefBuilder() | |||
.setColumnName("kee") | |||
.setIsNullable(false) | |||
.setLimit(400) | |||
.build(); | |||
private static final VarcharColumnDef QUALIFIER_COLUMN = newVarcharColumnDefBuilder() | |||
.setColumnName("qualifier") | |||
.setIsNullable(false) | |||
.setLimit(10) | |||
.build(); | |||
private static final VarcharColumnDef ORGANIZATION_UUID_COLUMN = newVarcharColumnDefBuilder() | |||
.setColumnName("organization_uuid") | |||
.setIsNullable(false) | |||
.setLimit(UUID_SIZE) | |||
.build(); | |||
private static final VarcharColumnDef NAME_COLUMN = newVarcharColumnDefBuilder() | |||
.setColumnName("name") | |||
.setLimit(2000) | |||
.build(); | |||
private static final VarcharColumnDef DESCRIPTION_COLUMN = newVarcharColumnDefBuilder() | |||
.setColumnName("description") | |||
.setLimit(2000) | |||
.build(); | |||
private static final BooleanColumnDef PRIVATE_COLUMN = newBooleanColumnDefBuilder() | |||
.setColumnName("private") | |||
.setIsNullable(false) | |||
.build(); | |||
private static final VarcharColumnDef TAGS_COLUMN = newVarcharColumnDefBuilder() | |||
.setColumnName("tags") | |||
.setLimit(500) | |||
.build(); | |||
private static final BigIntegerColumnDef CREATED_AT = newBigIntegerColumnDefBuilder() | |||
.setColumnName("created_at") | |||
.setIsNullable(false) | |||
.build(); | |||
private static final BigIntegerColumnDef UPDATED_AT = newBigIntegerColumnDefBuilder() | |||
.setColumnName("updated_at") | |||
.setIsNullable(false) | |||
.build(); | |||
public CreateProjectsTable(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
if (tableExists()) { | |||
return; | |||
} | |||
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME) | |||
.withPkConstraintName("pk_new_projects") | |||
.addPkColumn(UUID_COLUMN) | |||
.addColumn(KEE_COLUMN) | |||
.addColumn(QUALIFIER_COLUMN) | |||
.addColumn(ORGANIZATION_UUID_COLUMN) | |||
.addColumn(NAME_COLUMN) | |||
.addColumn(DESCRIPTION_COLUMN) | |||
.addColumn(PRIVATE_COLUMN) | |||
.addColumn(TAGS_COLUMN) | |||
.addColumn(CREATED_AT) | |||
.addColumn(UPDATED_AT) | |||
.build()); | |||
context.execute(new CreateIndexBuilder() | |||
.setTable(TABLE_NAME) | |||
.setName("uniq_projects_kee") | |||
.setUnique(true) | |||
.addColumn(KEE_COLUMN) | |||
.build()); | |||
context.execute(new CreateIndexBuilder() | |||
.setTable(TABLE_NAME) | |||
.setName("idx_qualifier") | |||
.addColumn(QUALIFIER_COLUMN) | |||
.build()); | |||
} | |||
private boolean tableExists() throws SQLException { | |||
try (Connection connection = getDatabase().getDataSource().getConnection()) { | |||
return DatabaseUtils.tableExists(TABLE_NAME, connection); | |||
} | |||
} | |||
} |
@@ -42,6 +42,10 @@ public class DbVersion81 implements DbVersion { | |||
RenameDaysBeforeDeletingInactiveSLBSetting.class) | |||
.add(3112, "Migrate short and long living branches types to common BRANCH type", MigrateSlbsAndLlbsToCommonType.class) | |||
.add(3113, "Migrate short and long living branches types to common BRANCH type in ce tasks table", | |||
MigrateSlbsAndLlbsToCommonTypeInCeTasks.class); | |||
MigrateSlbsAndLlbsToCommonTypeInCeTasks.class) | |||
.add(3114, "Rename table 'PROJECTS' to 'COMPONENTS'", RenameProjectsTableToComponents.class) | |||
.add(3115, "Add PROJECTS table", CreateProjectsTable.class) | |||
.add(3116, "Populate PROJECTS table", PopulateProjectsTable.class) | |||
; | |||
} | |||
} |
@@ -0,0 +1,62 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v81; | |||
import java.sql.SQLException; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.SupportsBlueGreen; | |||
import org.sonar.server.platform.db.migration.step.DataChange; | |||
import org.sonar.server.platform.db.migration.step.MassUpdate; | |||
@SupportsBlueGreen | |||
public class PopulateProjectsTable extends DataChange { | |||
private final System2 system; | |||
public PopulateProjectsTable(Database db, System2 system) { | |||
super(db); | |||
this.system = system; | |||
} | |||
@Override | |||
protected void execute(Context context) throws SQLException { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("select p.uuid, p.kee, p.qualifier, p.organization_uuid, p.name, p.description, p.private, p.tags, p.created_at " + | |||
"from components p " + | |||
"left join projects np on np.uuid = p.uuid " + | |||
"where p.scope = 'PRJ' and p.qualifier in ('TRK', 'APP') and np.uuid is null"); | |||
massUpdate.rowPluralName("projects"); | |||
massUpdate.update("insert into projects (uuid, kee, qualifier, organization_uuid, name, description, private, tags, created_at, updated_at) " + | |||
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); | |||
massUpdate.execute((row, update) -> { | |||
update.setString(1, row.getString(1)); | |||
update.setString(2, row.getString(2)); | |||
update.setString(3, row.getString(3)); | |||
update.setString(4, row.getString(4)); | |||
update.setString(5, row.getNullableString(5)); | |||
update.setString(6, row.getNullableString(6)); | |||
update.setBoolean(7, row.getBoolean(7)); | |||
update.setString(8, row.getNullableString(8)); | |||
update.setLong(9, row.getDate(9).getTime()); | |||
update.setLong(10, system.now()); | |||
return true; | |||
}); | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v81; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.sql.RenameTableBuilder; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
public class RenameProjectsTableToComponents extends DdlChange { | |||
public RenameProjectsTableToComponents(Database db) { | |||
super(db); | |||
} | |||
@Override public void execute(Context context) throws SQLException { | |||
context.execute(new RenameTableBuilder(getDialect()).setName("projects").setNewName("components").build()); | |||
} | |||
} |