aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2020-01-08 22:03:02 +0100
committerSonarTech <sonartech@sonarsource.com>2020-01-31 20:46:09 +0100
commit1ad6b113111429a43c009ecc92e793971109852b (patch)
tree4394c86b43b41c3e74703709d72cc518e956e96d /server
parentace9a50d55d831ec71b7db421aa04d1198392c6c (diff)
downloadsonarqube-1ad6b113111429a43c009ecc92e793971109852b.tar.gz
sonarqube-1ad6b113111429a43c009ecc92e793971109852b.zip
SONAR-12689 migrated tags, updated test framework
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java18
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java17
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java29
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/DbTagsReader.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectQuery.java10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml7
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl1
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java47
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java16
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java24
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java228
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java4
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java1
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTable.java40
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTableTest.java56
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTableTest/schema.sql47
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/es/ProjectIndexers.java1
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/project/Project.java4
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java19
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java4
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java6
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java53
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java32
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java39
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java26
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/projecttag/ws/SetAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/AnalysisStatusActionTest.java11
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ComponentDtoToWsComponentTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java59
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java14
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java12
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java1
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java14
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java2
51 files changed, 587 insertions, 334 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
index 9a553dbb77e..86d5c3d89db 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
@@ -37,8 +37,8 @@ import org.sonar.core.platform.PluginRepository;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin;
@@ -108,12 +108,13 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
"Compute Engine task main component key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
mainComponent.getUuid())));
CeTask.Component component = mandatoryComponent(ceTask.getComponent());
- String componentKey = component.getKey()
- .orElseThrow(() -> MessageException.of(format(
+ if (!component.getKey().isPresent()) {
+ throw MessageException.of(format(
"Compute Engine task component key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
- component.getUuid())));
- ComponentDto dto = toProject(reportMetadata.getProjectKey());
+ component.getUuid()));
+ }
+ ProjectDto dto = toProject(reportMetadata.getProjectKey());
analysisMetadata.setProject(Project.from(dto));
return () -> {
if (!mainComponentKey.equals(reportMetadata.getProjectKey())) {
@@ -125,9 +126,6 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
if (!dto.getOrganizationUuid().equals(organization.getUuid())) {
throw MessageException.of(format("Project is not in the expected organization: %s", organization.getKey()));
}
- if (componentKey.equals(mainComponentKey) && dto.getMainBranchProjectUuid() != null) {
- throw MessageException.of("Component should not reference a branch");
- }
};
}
@@ -222,9 +220,9 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
return Organization.from(organizationDto.get());
}
- private ComponentDto toProject(String projectKey) {
+ private ProjectDto toProject(String projectKey) {
try (DbSession dbSession = dbClient.openSession(false)) {
- Optional<ComponentDto> opt = dbClient.componentDao().selectByKey(dbSession, projectKey);
+ Optional<ProjectDto> opt = dbClient.projectDao().selectProjectByKey(dbSession, projectKey);
checkState(opt.isPresent(), "Project with key '%s' can't be found", projectKey);
return opt.get();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
index 71f2cbcf44a..7aa8e00db31 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
@@ -640,20 +640,33 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
return builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey()).setName(project.name());
}
- private ComponentDto prepareProject(Consumer<ComponentDto>... populators) {
+ private ComponentDto prepareProject() {
+ return prepareProject(defaults());
+ }
+
+ private ComponentDto prepareProject(Consumer<ComponentDto> populators) {
ComponentDto dto = db.components().insertPrivateProject(db.organizations().insert(), populators);
analysisMetadataHolder.setProject(Project.from(dto));
analysisMetadataHolder.setBranch(new DefaultBranchImpl());
return dto;
}
- private ComponentDto prepareBranch(String branchName, Consumer<ComponentDto>... populators) {
+ private ComponentDto prepareBranch(String branchName) {
+ return prepareBranch(branchName, defaults());
+ }
+
+ private ComponentDto prepareBranch(String branchName, Consumer<ComponentDto> populators) {
ComponentDto dto = db.components().insertPrivateProject(db.organizations().insert(), populators);
analysisMetadataHolder.setProject(Project.from(dto));
analysisMetadataHolder.setBranch(new TestBranch(branchName));
return dto;
}
+ private static <T> Consumer<T> defaults() {
+ return t -> {
+ };
+ }
+
private static class TestBranch implements Branch {
private final String name;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
index 54f0ba7b0df..ccda0b0c410 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -25,12 +25,10 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
-import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
@@ -43,15 +41,12 @@ import org.sonar.db.RowNotFoundException;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
-import static org.apache.commons.lang.StringUtils.isBlank;
import static org.sonar.core.util.stream.MoreCollectors.toList;
import static org.sonar.core.util.stream.MoreCollectors.toSet;
-import static org.sonar.db.DaoUtils.buildLikeValue;
import static org.sonar.db.DatabaseUtils.checkThatNotTooManyConditions;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
import static org.sonar.db.DatabaseUtils.executeLargeInputsIntoSet;
import static org.sonar.db.DatabaseUtils.executeLargeUpdates;
-import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER;
import static org.sonar.db.component.ComponentDto.generateBranchKey;
import static org.sonar.db.component.ComponentDto.generatePullRequestKey;
@@ -375,10 +370,6 @@ public class ComponentDao implements Dao {
mapper(session).update(component);
}
- public void updateTags(DbSession session, ComponentDto component) {
- mapper(session).updateTags(component);
- }
-
public void updateBEnabledToFalse(DbSession session, Collection<String> uuids) {
executeLargeUpdates(uuids, mapper(session)::updateBEnabledToFalse);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
index d364bc1d686..5e9c633eca9 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
@@ -19,7 +19,6 @@
*/
package org.sonar.db.component;
-import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import java.util.Date;
@@ -38,7 +37,6 @@ import static org.sonar.db.DaoUtils.buildLikeValue;
import static org.sonar.db.component.ComponentValidator.checkComponentKey;
import static org.sonar.db.component.ComponentValidator.checkComponentLongName;
import static org.sonar.db.component.ComponentValidator.checkComponentName;
-import static org.sonar.db.component.DbTagsReader.readDbTags;
public class ComponentDto {
@@ -56,9 +54,6 @@ public class ComponentDto {
public static final String UUID_PATH_OF_ROOT = UUID_PATH_SEPARATOR;
private static final Splitter UUID_PATH_SPLITTER = Splitter.on(UUID_PATH_SEPARATOR).omitEmptyStrings();
- static final char TAGS_SEPARATOR = ',';
- private static final Joiner TAGS_JOINER = Joiner.on(TAGS_SEPARATOR).skipNulls();
-
/**
* ID generated by database. Do not use.
*/
@@ -151,7 +146,6 @@ public class ComponentDto {
private String longName;
private String language;
private String description;
- private String tags;
private boolean enabled = true;
private boolean isPrivate = false;
@@ -407,28 +401,6 @@ public class ComponentDto {
return moduleUuid == null && Scopes.PROJECT.equals(scope);
}
- public List<String> getTags() {
- return readDbTags(tags);
- }
-
- public ComponentDto setTags(List<String> tags) {
- setTagsString(TAGS_JOINER.join(tags));
- return this;
- }
-
- /**
- * Used by MyBatis
- */
- @CheckForNull
- public String getTagsString() {
- return tags;
- }
-
- public ComponentDto setTagsString(@Nullable String tags) {
- this.tags = tags;
- return this;
- }
-
public boolean isPrivate() {
return isPrivate;
}
@@ -501,7 +473,6 @@ public class ComponentDto {
copy.longName = longName;
copy.language = language;
copy.description = description;
- copy.tags = tags;
copy.enabled = enabled;
copy.isPrivate = isPrivate;
copy.createdAt = createdAt;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
index e8ebd2c116a..0626ee076ac 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
@@ -156,8 +156,6 @@ public interface ComponentMapper {
void delete(long componentId);
- void updateTags(ComponentDto component);
-
List<KeyWithUuidDto> selectAllSiblingComponentKeysHavingOpenIssues(@Param("referenceBranchUuid") String referenceBranchUuid,
@Param("currentBranchUuid") String currentBranchUuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/DbTagsReader.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/DbTagsReader.java
index 1ddb344b698..a9a0caffeb7 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/DbTagsReader.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/DbTagsReader.java
@@ -24,9 +24,9 @@ import java.util.List;
import javax.annotation.Nullable;
import static com.google.common.base.Strings.nullToEmpty;
-import static org.sonar.db.component.ComponentDto.TAGS_SEPARATOR;
public class DbTagsReader {
+ private static final char TAGS_SEPARATOR = ',';
private static final Splitter TAGS_SPLITTER = Splitter.on(TAGS_SEPARATOR).trimResults().omitEmptyStrings();
private DbTagsReader() {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
index 6892169d1b3..6e905990291 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
@@ -40,7 +40,6 @@ import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
import org.sonar.core.util.CloseableIterator;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
@@ -72,8 +71,9 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
// 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 components cp on p.uuid = cp.uuid " +
"LEFT OUTER JOIN snapshots s ON s.component_uuid=p.uuid AND s.islast=? " +
- "WHERE p.qualifier=?";
+ "WHERE cp.enabled=? AND p.qualifier=?";
private static final String PROJECT_FILTER = " AND p.uuid=?";
@@ -131,9 +131,10 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
}
PreparedStatement stmt = session.getConnection().prepareStatement(sql.toString());
stmt.setBoolean(1, true);
- stmt.setString(2, Qualifiers.PROJECT);
+ stmt.setBoolean(2, true);
+ stmt.setString(3, Qualifiers.PROJECT);
if (projectUuid != null) {
- stmt.setString(3, projectUuid);
+ stmt.setString(4, projectUuid);
}
return stmt;
} catch (SQLException e) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
index 25550fac2d2..4f47bcb49c0 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
@@ -74,6 +74,10 @@ public class ProjectDao implements Dao {
return mapper(session).selectByUuids(uuids);
}
+ public void updateKey(DbSession session, String uuid, String newKey) {
+ mapper(session).updateKey(uuid, newKey);
+ }
+
public void updateTags(DbSession session, ProjectDto project) {
mapper(session).updateTags(project);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java
index 754358ff2fe..017dc94fc14 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java
@@ -44,7 +44,9 @@ public interface ProjectMapper {
List<ProjectDto> selectByUuids(@Param("uuids") Collection<String> uuids);
- List<ProjectDto> selectByOrganizationUuid(String organizationUuid);
+ List<ProjectDto> selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid);
+
+ void updateKey(@Param("uuid") String uuid, @Param("newKey") String newKey);
void updateTags(ProjectDto project);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectQuery.java
index 266191ec81f..49f713a8560 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectQuery.java
@@ -129,6 +129,7 @@ public class ProjectQuery {
private Boolean isPrivate;
private Set<String> projectUuids;
private Set<String> projectKeys;
+ private Set<String> qualifiers;
private Long analyzedBefore;
private Long anyBranchAnalyzedBefore;
private Long anyBranchAnalyzedAfter;
@@ -158,6 +159,15 @@ public class ProjectQuery {
return this;
}
+ public Set<String> getQualifiers() {
+ return qualifiers;
+ }
+
+ public ProjectQuery.Builder setQualifiers(Set<String> qualifiers) {
+ this.qualifiers = qualifiers;
+ return this;
+ }
+
public ProjectQuery.Builder setPrivate(@Nullable Boolean isPrivate) {
this.isPrivate = isPrivate;
return this;
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 3acf8b919bf..6eb7660e890 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -15,7 +15,6 @@
p.name as name,
p.long_name as longName,
p.description as description,
- p.tags as tagsString,
p.qualifier as qualifier,
p.scope as scope,
p.language as language,
@@ -583,7 +582,6 @@
language,
description,
private,
- tags,
root_uuid,
path,
copy_component_uuid,
@@ -618,7 +616,6 @@
#{language,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR},
#{isPrivate,jdbcType=BOOLEAN},
- #{tagsString, jdbcType=VARCHAR},
#{rootUuid,jdbcType=VARCHAR},
#{path,jdbcType=VARCHAR},
#{copyComponentUuid,jdbcType=VARCHAR},
@@ -639,13 +636,6 @@
)
</insert>
- <update id="updateTags" parameterType="Component" useGeneratedKeys="false">
- 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 components set
b_changed = #{bChanged,jdbcType=BOOLEAN},
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
index 761d1f01e49..e1d70003f07 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
@@ -141,4 +141,11 @@
uuid = #{uuid,jdbcType=VARCHAR}
</update>
+ <update id="updateKey" parameterType="String">
+ update projects set
+ kee = #{newKey,jdbcType=VARCHAR}
+ where
+ uuid = #{uuid,jdbcType=VARCHAR}
+ </update>
+
</mapper>
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 16d5ae1174a..9f288bf959a 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -186,7 +186,6 @@ CREATE TABLE "COMPONENTS"(
"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),
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index dc4e353c7b0..bd105e39d18 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -56,10 +56,8 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.source.FileSourceDto;
import static com.google.common.collect.ImmutableSet.of;
-import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;
import static java.util.Arrays.asList;
-import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
@@ -326,15 +324,15 @@ public class ComponentDaoTest {
assertThat(underTest.selectByKeysAndBranches(db.getSession(), ImmutableMap.of(
projectBranch.getKey(), projectBranch.getBranch(),
applicationBranch.getKey(), applicationBranch.getBranch())))
- .extracting(ComponentDto::getKey, ComponentDto::getBranch)
- .containsExactlyInAnyOrder(
- tuple(projectBranch.getKey(), "my_branch"),
- tuple(applicationBranch.getKey(), "my_branch"));
+ .extracting(ComponentDto::getKey, ComponentDto::getBranch)
+ .containsExactlyInAnyOrder(
+ tuple(projectBranch.getKey(), "my_branch"),
+ tuple(applicationBranch.getKey(), "my_branch"));
assertThat(underTest.selectByKeysAndBranches(db.getSession(), ImmutableMap.of(
projectBranch.getKey(), "unknown",
"unknown", projectBranch.getBranch())))
- .extracting(ComponentDto::getDbKey)
- .isEmpty();
+ .extracting(ComponentDto::getDbKey)
+ .isEmpty();
assertThat(underTest.selectByKeysAndBranches(db.getSession(), Collections.emptyMap())).isEmpty();
}
@@ -733,7 +731,7 @@ public class ComponentDaoTest {
db.components().insertView(organization, "IJKL");
ComponentDto view = db.components().insertView(organization, "EFGH");
db.components().insertSubView(view, dto -> dto.setUuid("FGHI"));
- ComponentDto application = db.components().insertApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication(organization);
assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getUuid)
.containsExactlyInAnyOrder("ABCD", "EFGH", "FGHI", "IJKL", application.uuid());
@@ -759,7 +757,7 @@ public class ComponentDaoTest {
@DataProvider
public static Object[][] oneOrMoreProjects() {
- return new Object[][]{
+ return new Object[][] {
{1},
{1 + new Random().nextInt(10)}
};
@@ -988,7 +986,7 @@ public class ComponentDaoTest {
@DataProvider
public static Object[][] portfolioOrApplicationRootViewQualifier() {
- return new Object[][]{
+ return new Object[][] {
{Qualifiers.VIEW},
{Qualifiers.APP},
};
@@ -1003,8 +1001,11 @@ public class ComponentDaoTest {
return lowestView;
}
- @SafeVarargs
- private final ComponentDto insertView(OrganizationDto organization, String rootViewQualifier, Consumer<ComponentDto>... dtoPopulators) {
+ private ComponentDto insertView(OrganizationDto organization, String rootViewQualifier) {
+ return insertView(organization, rootViewQualifier, defaults());
+ }
+
+ private ComponentDto insertView(OrganizationDto organization, String rootViewQualifier, Consumer<ComponentDto> dtoPopulators) {
ComponentDbTester tester = db.components();
if (rootViewQualifier.equals(Qualifiers.VIEW)) {
return random.nextBoolean() ? tester.insertPublicPortfolio(organization, dtoPopulators) : tester.insertPrivatePortfolio(organization, dtoPopulators);
@@ -1076,7 +1077,7 @@ public class ComponentDaoTest {
ComponentDto file = db.components().insertComponent(newFileDto(module, directory));
ComponentDto project2 = db.components().insertPrivateProject(organization);
ComponentDto view = db.components().insertView(organization);
- ComponentDto application = db.components().insertApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication(organization);
OrganizationDto otherOrganization = db.organizations().insert();
ComponentDto projectOnOtherOrganization = db.components().insertPrivateProject(otherOrganization);
@@ -1189,8 +1190,7 @@ public class ComponentDaoTest {
.containsExactly(
project1.uuid(),
project2.uuid(),
- project3.uuid()
- );
+ project3.uuid());
}
@Test
@@ -1400,16 +1400,6 @@ public class ComponentDaoTest {
}
@Test
- public void update_tags() {
- ComponentDto project = db.components().insertPrivateProject(p -> p.setTags(emptyList()));
-
- underTest.updateTags(dbSession, project.setTags(newArrayList("finance", "toto", "tutu")));
- dbSession.commit();
-
- assertThat(underTest.selectOrFailByKey(dbSession, project.getDbKey()).getTags()).containsOnly("finance", "toto", "tutu");
- }
-
- @Test
public void delete() {
ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setDbKey("PROJECT_1"));
db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setDbKey("PROJECT_2"));
@@ -2002,4 +1992,9 @@ public class ComponentDaoTest {
db.measures().insertLiveMeasure(componentDto, metric, m -> m.setValue(value));
}
+ private static <T> Consumer<T> defaults() {
+ return t -> {
+ };
+ }
+
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
index 770738e9106..f02294b57c7 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
@@ -36,7 +36,9 @@ import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
+import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.sonar.api.measures.Metric.Level.ERROR;
@@ -62,7 +64,11 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_project_measure() {
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization, p -> p.setDbKey("Project-Key").setName("Project Name").setTagsString("platform,java"));
+ ComponentDto project = dbTester.components().insertPrivateProject(organization,
+ c -> c.setDbKey("Project-Key").setName("Project Name"),
+ p -> p.setTags(newArrayList("platform", "java")));
+ ProjectDto projectDto = dbTester.components().getProjectDto(project);
+
SnapshotDto analysis = dbTester.components().insertSnapshot(project);
MetricDto metric1 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc"));
MetricDto metric2 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("coverage"));
@@ -85,7 +91,9 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_project_measure_having_leak() {
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization, p -> p.setDbKey("Project-Key").setName("Project Name").setTagsString("platform,java"));
+ ComponentDto project = dbTester.components().insertPrivateProject(organization,
+ c -> c.setDbKey("Project-Key").setName("Project Name"),
+ p -> p.setTagsString("platform,java"));
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines"));
dbTester.measures().insertLiveMeasure(project, metric, m -> m.setVariation(10d));
@@ -207,7 +215,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_project_without_analysis() {
- ComponentDto project = dbTester.components().insertPrivateProject(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
+ ComponentDto project = dbTester.components().insertPrivateProject(dbTester.organizations().insert());
dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setLast(false));
dbSession.commit();
@@ -220,7 +228,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
@Ignore
- //TODO
+ // TODO
public void does_not_return_non_active_projects() {
OrganizationDto organization = dbTester.organizations().insert();
// Disabled project
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java
index 8b6f6b6e69b..33536a670d1 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java
@@ -94,7 +94,7 @@ public class PurgeMapperTest {
@Test
public void selectRootAndModulesOrSubviewsByProjectUuid_returns_application_with_specified_uuid() {
- ComponentDto view = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto view = db.components().insertPublicApplication(db.getDefaultOrganization());
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
.extracting(IdUuidPair::getUuid)
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
index 2e8ec49fe34..7b257ff29b8 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
@@ -743,11 +743,11 @@ public class QualityProfileDaoTest {
@Test
public void select_selected_projects() {
- ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name").setOrganizationUuid(organization.getUuid()));
+ ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name").setOrganizationUuid(organization.getUuid()));
+ ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name").setOrganizationUuid(organization.getUuid()));
OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+ ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name").setOrganizationUuid(organization2.getUuid()));
ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
@@ -772,11 +772,11 @@ public class QualityProfileDaoTest {
@Test
public void select_deselected_projects() {
- ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name").setOrganizationUuid(organization.getUuid()));
+ ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name").setOrganizationUuid(organization.getUuid()));
+ ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name").setOrganizationUuid(organization.getUuid()));
OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+ ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name").setOrganizationUuid(organization2.getUuid()));
ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
@@ -800,11 +800,11 @@ public class QualityProfileDaoTest {
@Test
public void select_project_associations() {
- ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name").setOrganizationUuid(organization.getUuid()));
+ ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name").setOrganizationUuid(organization.getUuid()));
+ ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name").setOrganizationUuid(organization.getUuid()));
OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+ ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name").setOrganizationUuid(organization2.getUuid()));
ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
index 3ca21fd8abf..8b3f6c50e89 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
@@ -47,7 +47,7 @@ public class ComponentDbTester {
}
public SnapshotDto insertProjectAndSnapshot(ComponentDto component) {
- insertComponentAndBranchAndProject(component, null, noExtraConfiguration());
+ insertComponentAndBranchAndProject(component, null, defaults(), defaults(), defaults());
return insertSnapshot(component);
}
@@ -57,55 +57,72 @@ public class ComponentDbTester {
}
public ComponentDto insertComponent(ComponentDto component) {
- return insertComponentImpl(component, null, noExtraConfiguration());
+ return insertComponentImpl(component, null, defaults());
}
public ComponentDto insertPrivateProject() {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, noExtraConfiguration());
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true,
+ defaults(), defaults(), defaults());
}
public ProjectDto getProjectDto(ComponentDto project) {
- return db.getDbClient().projectDao().selectByUuid(dbSession, project.uuid()).get();
+ return db.getDbClient().projectDao().selectByUuid(dbSession, project.uuid())
+ .orElseThrow(() -> new IllegalStateException("Project has invalid configuration"));
}
public ComponentDto insertPrivateProject(ComponentDto componentDto) {
- return insertComponentAndBranchAndProject(componentDto, true, noExtraConfiguration());
+ return insertComponentAndBranchAndProject(componentDto, true);
}
public ComponentDto insertPublicProject() {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, noExtraConfiguration());
+ return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false);
}
public ComponentDto insertPublicProject(ComponentDto componentDto) {
- return insertComponentAndBranchAndProject(componentDto, false, noExtraConfiguration());
+ return insertComponentAndBranchAndProject(componentDto, false);
}
- @SafeVarargs
- public final ComponentDto insertPrivateProject(Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, null, dtoPopulators);
+ public final ComponentDto insertPrivateProject(Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, defaults(),
+ dtoPopulator);
}
- @SafeVarargs
- public final ComponentDto insertPublicProject(Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, null, dtoPopulators);
+ public final ComponentDto insertPrivateProject(Consumer<ComponentDto> componentDtoPopulator, Consumer<ProjectDto> projectDtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()),
+ true, defaults(), componentDtoPopulator, projectDtoPopulator);
}
- @SafeVarargs
- public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, null, dtoPopulators);
+ public final ComponentDto insertPublicProject(Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, defaults(),
+ dtoPopulator);
}
- @SafeVarargs
- public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false, null, dtoPopulators);
+ public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator) {
+ return insertPrivateProject(organizationDto, componentDtoPopulator, defaults());
+ }
+
+ public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator,
+ Consumer<ProjectDto> projectDtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, defaults(),
+ componentDtoPopulator, projectDtoPopulator);
+ }
+
+ public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator) {
+ return insertPublicProject(organizationDto, componentDtoPopulator, defaults());
+ }
+
+ public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator,
+ Consumer<ProjectDto> projectDtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false, defaults(), componentDtoPopulator,
+ projectDtoPopulator);
}
public ComponentDto insertPrivateProject(OrganizationDto organizationDto) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, noExtraConfiguration());
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true);
}
public ComponentDto insertPublicProject(OrganizationDto organizationDto) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false, noExtraConfiguration());
+ return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false);
}
public ProjectDto insertPublicProjectDto() {
@@ -123,9 +140,8 @@ public class ComponentDbTester {
return getProjectDto(componentDto);
}
- @SafeVarargs
- public final ProjectDto insertPublicProjectDto(OrganizationDto organization, Consumer<ComponentDto>... dtoPopulators) {
- ComponentDto componentDto = insertPublicProject(organization, dtoPopulators);
+ public final ProjectDto insertPublicProjectDto(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
+ ComponentDto componentDto = insertPublicProject(organization, dtoPopulator);
return getProjectDto(componentDto);
}
@@ -134,47 +150,52 @@ public class ComponentDbTester {
return getProjectDto(componentDto);
}
- @SafeVarargs
- public final ProjectDto insertPrivateProjectDto(Consumer<ComponentDto>... dtoPopulators) {
- ComponentDto componentDto = insertPrivateProject(dtoPopulators);
+ public final ProjectDto insertPrivateProjectDto(Consumer<ComponentDto> componentDtoPopulator) {
+ return insertPrivateProjectDto(componentDtoPopulator, defaults());
+ }
+
+ public final ProjectDto insertPrivateProjectDto(Consumer<ComponentDto> componentDtoPopulator, Consumer<ProjectDto> projectDtoPopulator) {
+ ComponentDto componentDto = insertPrivateProject(componentDtoPopulator, projectDtoPopulator);
return getProjectDto(componentDto);
}
public ProjectDto insertPrivateProjectDto(OrganizationDto organization, Consumer<BranchDto> branchConsumer) {
- ComponentDto componentDto = insertPrivateProjectWithCustomBranch(organization, branchConsumer);
+ ComponentDto componentDto = insertPrivateProjectWithCustomBranch(organization, branchConsumer, defaults());
return getProjectDto(componentDto);
}
public ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, noExtraConfiguration());
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true);
}
public ComponentDto insertPublicProject(OrganizationDto organizationDto, String uuid) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto, uuid), false, noExtraConfiguration());
+ return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto, uuid), false);
}
- @SafeVarargs
- public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, null, dtoPopulators);
+ public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, defaults(), dtoPopulator);
+ }
+
+ public final ComponentDto insertPrivateProjectWithCustomBranch(OrganizationDto organizationDto, Consumer<BranchDto> branchPopulator) {
+ return insertPrivateProjectWithCustomBranch(organizationDto, branchPopulator, defaults());
}
- @SafeVarargs
public final ComponentDto insertPrivateProjectWithCustomBranch(OrganizationDto organizationDto, Consumer<BranchDto> branchPopulator,
- Consumer<ComponentDto>... componentPopulator) {
+ Consumer<ComponentDto> componentPopulator) {
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, branchPopulator, componentPopulator);
}
/**
- * @see #insertPublicPortfolio(OrganizationDto, Consumer[])
+ * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
* @deprecated since 6.6
*/
@Deprecated
public ComponentDto insertView() {
- return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()), false, noExtraConfiguration());
+ return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()), false);
}
/**
- * @see #insertPublicPortfolio(OrganizationDto, Consumer[])
+ * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
* @deprecated since 6.6
*/
public ComponentDto insertView(Consumer<ComponentDto> dtoPopulator) {
@@ -182,15 +203,15 @@ public class ComponentDbTester {
}
/**
- * @see #insertPublicPortfolio(OrganizationDto, Consumer[])
+ * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
* @deprecated since 6.6
*/
public ComponentDto insertView(OrganizationDto organizationDto) {
- return insertComponentImpl(ComponentTesting.newView(organizationDto), false, noExtraConfiguration());
+ return insertComponentImpl(ComponentTesting.newView(organizationDto), false, defaults());
}
/**
- * @see #insertPublicPortfolio(OrganizationDto, Consumer[])
+ * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
* @deprecated since 6.6
*/
public ComponentDto insertView(OrganizationDto organizationDto, Consumer<ComponentDto> dtoPopulator) {
@@ -198,101 +219,105 @@ public class ComponentDbTester {
}
/**
- * @see #insertPublicPortfolio(OrganizationDto, Consumer[])
+ * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
* @deprecated since 6.6
*/
public ComponentDto insertView(String uuid) {
- return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization(), uuid), false, noExtraConfiguration());
+ return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization(), uuid), false, defaults());
}
/**
- * @see #insertPublicPortfolio(OrganizationDto, Consumer[])
+ * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
* @deprecated since 6.6
*/
public ComponentDto insertView(OrganizationDto organizationDto, String uuid) {
- return insertComponentImpl(ComponentTesting.newView(organizationDto, uuid), false, noExtraConfiguration());
+ return insertComponentImpl(ComponentTesting.newView(organizationDto, uuid), false, defaults());
}
- @SafeVarargs
- public final ComponentDto insertPublicPortfolio(OrganizationDto organization, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(false), false, dtoPopulators);
+ public final ComponentDto insertPublicPortfolio(OrganizationDto organization) {
+ return insertPublicPortfolio(organization, defaults());
}
- @SafeVarargs
- public final ComponentDto insertPrivatePortfolio(Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()).setPrivate(true), true, dtoPopulators);
+ public final ComponentDto insertPublicPortfolio(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(false), false, dtoPopulator);
}
- @SafeVarargs
- public final ComponentDto insertPrivatePortfolio(OrganizationDto organization, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(true), true, dtoPopulators);
+ public final ComponentDto insertPrivatePortfolio() {
+ return insertPrivatePortfolio(db.getDefaultOrganization());
}
- @SafeVarargs
- public final ComponentDto insertPublicApplication(Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentImpl(ComponentTesting.newApplication(db.getDefaultOrganization()).setPrivate(false), false, dtoPopulators);
+ public final ComponentDto insertPrivatePortfolio(OrganizationDto organization) {
+ return insertPrivatePortfolio(organization, defaults());
}
- @SafeVarargs
- public final ComponentDto insertPublicApplication(OrganizationDto organization, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(false), false, b -> {
- }, dtoPopulators);
+ public final ComponentDto insertPrivatePortfolio(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(true), true, dtoPopulator);
}
- @SafeVarargs
- public final ComponentDto insertPrivateApplication(Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentImpl(ComponentTesting.newApplication(db.getDefaultOrganization()).setPrivate(true), true, dtoPopulators);
+ public final ComponentDto insertPublicApplication() {
+ return insertPublicApplication(db.getDefaultOrganization());
}
- @SafeVarargs
- public final ComponentDto insertPrivateApplication(OrganizationDto organization, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(true), true, b -> {
- }, dtoPopulators);
+ public final ComponentDto insertPublicApplication(OrganizationDto organization) {
+ return insertPublicApplication(organization, defaults());
}
- /**
- * @see #insertPublicApplication(OrganizationDto, Consumer[])
- * @deprecated since 6.6
- */
- @SafeVarargs
- public final ComponentDto insertApplication(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organizationDto), false, b -> {
- }, dtoPopulators);
+ public final ComponentDto insertPublicApplication(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(false), false, defaults(), dtoPopulator);
}
- @SafeVarargs
- public final ComponentDto insertSubView(ComponentDto view, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentAndBranchAndProject(ComponentTesting.newSubView(view), view.isPrivate(), null, dtoPopulators);
+ public final ComponentDto insertPrivateApplication() {
+ return insertPrivateApplication(db.getDefaultOrganization());
+ }
+
+ public final ComponentDto insertPrivateApplication(OrganizationDto organization) {
+ return insertPrivateApplication(organization, defaults());
}
- private static <T> Consumer<T> noExtraConfiguration() {
- return (t) -> {
- };
+ public final ComponentDto insertPrivateApplication(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(true), true, defaults(), dtoPopulator);
}
- @SafeVarargs
- private final ComponentDto insertComponentAndBranchAndProject(ComponentDto component, @Nullable Boolean isPrivate, @Nullable Consumer<BranchDto> branchPopulator,
- Consumer<ComponentDto>... dtoPopulators) {
- insertComponentImpl(component, isPrivate, dtoPopulators);
+ public final ComponentDto insertSubView(ComponentDto view) {
+ return insertSubView(view, defaults());
+ }
+
+ public final ComponentDto insertSubView(ComponentDto view, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newSubView(view), view.isPrivate(), defaults(), dtoPopulator);
+ }
+
+ private ComponentDto insertComponentAndBranchAndProject(ComponentDto component, @Nullable Boolean isPrivate, Consumer<BranchDto> branchPopulator,
+ Consumer<ComponentDto> componentDtoPopulator, Consumer<ProjectDto> projectDtoPopulator) {
+ insertComponentImpl(component, isPrivate, componentDtoPopulator);
ProjectDto projectDto = toProjectDto(component, System2.INSTANCE.now());
+ projectDtoPopulator.accept(projectDto);
dbClient.projectDao().insert(dbSession, projectDto);
BranchDto branchDto = ComponentTesting.newBranchDto(component, BRANCH);
branchDto.setExcludeFromPurge(true);
-
- if (branchPopulator != null) {
- branchPopulator.accept(branchDto);
- }
+ 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));
+ private ComponentDto insertComponentAndBranchAndProject(ComponentDto component, @Nullable Boolean isPrivate, Consumer<BranchDto> branchPopulator,
+ Consumer<ComponentDto> componentDtoPopulator) {
+ return insertComponentAndBranchAndProject(component, isPrivate, branchPopulator, componentDtoPopulator, defaults());
+ }
+
+ private ComponentDto insertComponentAndBranchAndProject(ComponentDto component, @Nullable Boolean isPrivate, Consumer<BranchDto> branchPopulator) {
+ return insertComponentAndBranchAndProject(component, isPrivate, branchPopulator, defaults());
+ }
+
+ private ComponentDto insertComponentAndBranchAndProject(ComponentDto component, @Nullable Boolean isPrivate) {
+ return insertComponentAndBranchAndProject(component, isPrivate, defaults());
+ }
+
+ private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate, Consumer<ComponentDto> dtoPopulator) {
+ dtoPopulator.accept(component);
checkState(isPrivate == null || component.isPrivate() == isPrivate, "Illegal modification of private flag");
dbClient.componentDao().insert(dbSession, component);
db.commit();
@@ -300,6 +325,10 @@ public class ComponentDbTester {
return component;
}
+ private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate) {
+ return insertComponentImpl(component, isPrivate, defaults());
+ }
+
public void insertComponents(ComponentDto... components) {
dbClient.componentDao().insert(dbSession, asList(components));
db.commit();
@@ -312,7 +341,7 @@ public class ComponentDbTester {
}
public SnapshotDto insertSnapshot(ComponentDto componentDto) {
- return insertSnapshot(componentDto, noExtraConfiguration());
+ return insertSnapshot(componentDto, defaults());
}
public SnapshotDto insertSnapshot(ComponentDto componentDto, Consumer<SnapshotDto> consumer) {
@@ -322,7 +351,7 @@ public class ComponentDbTester {
}
public SnapshotDto insertSnapshot(BranchDto branchDto) {
- return insertSnapshot(branchDto, noExtraConfiguration());
+ return insertSnapshot(branchDto, defaults());
}
public SnapshotDto insertSnapshot(BranchDto branchDto, Consumer<SnapshotDto> consumer) {
@@ -392,8 +421,11 @@ public class ComponentDbTester {
.setPrivate(componentDto.isPrivate())
.setDescription(componentDto.description())
.setName(componentDto.name())
- .setOrganizationUuid(componentDto.getOrganizationUuid())
- .setTags(componentDto.getTags())
- .setTagsString(componentDto.getTagsString());
+ .setOrganizationUuid(componentDto.getOrganizationUuid());
+ }
+
+ private static <T> Consumer<T> defaults() {
+ return t -> {
+ };
}
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java
index 1f76a826c89..544395d5aa0 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java
@@ -26,6 +26,10 @@ import static org.apache.commons.lang.RandomStringUtils.randomAscii;
public class SnapshotTesting {
+ private SnapshotTesting() {
+ // nothing to do
+ }
+
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");
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java
index bf10947b099..b503ce6f8a0 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java
@@ -46,6 +46,7 @@ public class DbVersion81 implements DbVersion {
.add(3114, "Rename table 'PROJECTS' to 'COMPONENTS'", RenameProjectsTableToComponents.class)
.add(3115, "Add PROJECTS table", CreateProjectsTable.class)
.add(3116, "Populate PROJECTS table", PopulateProjectsTable.class)
+ .add(3117, "Drop 'TAGS' column from COMPONENTS table", DropTagsColumnFromComponentsTable.class)
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTable.java
new file mode 100644
index 00000000000..9f6456d5616
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTable.java
@@ -0,0 +1,40 @@
+/*
+ * 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.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropTagsColumnFromComponentsTable extends DdlChange {
+
+ static final String TABLE = "components";
+ static final String COLUMN_TO_DROP = "tags";
+
+ public DropTagsColumnFromComponentsTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE, COLUMN_TO_DROP).build());
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java
index c533f92f79c..ff45a3e9f78 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java
@@ -36,7 +36,7 @@ public class DbVersion81Test {
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 17);
+ verifyMigrationCount(underTest, 18);
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTableTest.java
new file mode 100644
index 00000000000..b45b97bc8d9
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTableTest.java
@@ -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.server.platform.db.migration.version.v81;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static org.sonar.server.platform.db.migration.version.v81.DropTagsColumnFromComponentsTable.COLUMN_TO_DROP;
+import static org.sonar.server.platform.db.migration.version.v81.DropTagsColumnFromComponentsTable.TABLE;
+
+public class DropTagsColumnFromComponentsTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropTagsColumnFromComponentsTableTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private DropTagsColumnFromComponentsTable underTest = new DropTagsColumnFromComponentsTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist(TABLE, COLUMN_TO_DROP);
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist(TABLE, COLUMN_TO_DROP);
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTableTest/schema.sql
new file mode 100644
index 00000000000..fda0c51c86c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropTagsColumnFromComponentsTableTest/schema.sql
@@ -0,0 +1,47 @@
+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");
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/ProjectIndexers.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/ProjectIndexers.java
index 51e5b721d31..b7343f4e47b 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/es/ProjectIndexers.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/ProjectIndexers.java
@@ -37,6 +37,7 @@ public interface ProjectIndexers {
*/
void commitAndIndexByProjectUuids(DbSession dbSession, Collection<String> projectUuids, ProjectIndexer.Cause cause);
+ //TODO remove?
default void commitAndIndex(DbSession dbSession, Collection<ComponentDto> projectOrModules, ProjectIndexer.Cause cause) {
Collection<String> projectUuids = projectOrModules.stream()
.map(ComponentDto::projectUuid)
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/project/Project.java b/server/sonar-server-common/src/main/java/org/sonar/server/project/Project.java
index 9c45cdbed32..b3c15295f8c 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/project/Project.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/project/Project.java
@@ -26,6 +26,8 @@ import javax.annotation.concurrent.Immutable;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
+import static java.util.Collections.emptyList;
+
@Immutable
public class Project {
@@ -44,7 +46,7 @@ public class Project {
}
public static Project from(ComponentDto project) {
- return new Project(project.uuid(), project.getKey(), project.name(), project.description(), project.getTags());
+ return new Project(project.uuid(), project.getKey(), project.name(), project.description(), emptyList());
}
public static Project from(ProjectDto project) {
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java
index f547363413d..1335c5de1ab 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java
@@ -21,6 +21,7 @@ package org.sonar.server.measure.index;
import java.util.Arrays;
import java.util.Collection;
+import java.util.function.Consumer;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.search.SearchHit;
import org.junit.Rule;
@@ -32,6 +33,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.es.EsQueueDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.IndexingResult;
import org.sonar.server.es.ProjectIndexer;
@@ -137,15 +139,14 @@ public class ProjectMeasuresIndexerTest {
@Test
public void update_index_when_project_tags_are_updated() {
- ComponentDto project = db.components().insertPrivateProject(p -> p.setTagsString("foo"));
+ ComponentDto project = db.components().insertPrivateProject(defaults(), p -> p.setTagsString("foo"));
indexProject(project, PROJECT_CREATION);
assertThatProjectHasTag(project, "foo");
- project.setTagsString("bar");
- // TODO this should be removed at some point
- db.getDbClient().componentDao().updateTags(db.getSession(), project);
- db.getDbClient().projectDao().updateTags(db.getSession(), db.components().getProjectDto(project).setTagsString("bar"));
-
+ ProjectDto projectDto = db.components().getProjectDto(project);
+ projectDto.setTagsString("bar");
+ db.getDbClient().projectDao().updateTags(db.getSession(), projectDto);
+ // TODO change indexing?
IndexingResult result = indexProject(project, PROJECT_TAGS_UPDATE);
assertThatProjectHasTag(project, "bar");
@@ -249,4 +250,10 @@ public class ProjectMeasuresIndexerTest {
return underTest.index(db.getSession(), items);
}
+ private static <T> Consumer<T> defaults() {
+ return t -> {
+ // do nothing
+ };
+ }
+
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
index 9ab7c12bf30..c5174244c67 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
@@ -138,7 +138,7 @@ public class ViewIndexerTest {
@Test
public void index_application() {
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization());
ComponentDto project = db.components().insertPrivateProject();
db.components().insertComponent(newProjectCopy("PC1", project, application));
@@ -153,7 +153,7 @@ public class ViewIndexerTest {
@Test
public void index_application_on_startup() {
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization());
ComponentDto project = db.components().insertPrivateProject();
db.components().insertComponent(newProjectCopy("PC1", project, application));
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
index 28922bbf6dc..050eb283ae7 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
@@ -263,7 +263,7 @@ public class IssueQueryFactoryTest {
public void application_search_project_issues() {
ComponentDto project1 = db.components().insertPublicProject();
ComponentDto project2 = db.components().insertPublicProject();
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization());
db.components().insertComponents(newProjectCopy("PC1", project1, application));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
userSession.registerComponents(application, project1, project2);
@@ -279,9 +279,9 @@ public class IssueQueryFactoryTest {
ComponentDto project1 = db.components().insertPublicProject();
SnapshotDto analysis1 = db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
ComponentDto project2 = db.components().insertPublicProject();
- SnapshotDto analysis2 = db.components().insertSnapshot(project2, s -> s.setPeriodDate(null));
+ db.components().insertSnapshot(project2, s -> s.setPeriodDate(null));
ComponentDto project3 = db.components().insertPublicProject();
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization());
db.components().insertComponents(newProjectCopy("PC1", project1, application));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
db.components().insertComponents(newProjectCopy("PC3", project3, application));
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
index c6aa6438261..55f31f0795b 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
@@ -83,7 +83,7 @@ public class PermissionIndexerDaoTest {
privateProject2 = componentDbTester.insertPrivateProject(organization);
view1 = componentDbTester.insertView(organization);
view2 = componentDbTester.insertView(organization);
- application = componentDbTester.insertApplication(organization);
+ application = componentDbTester.insertPublicApplication(organization);
user1 = userDbTester.insertUser();
user2 = userDbTester.insertUser();
group = userDbTester.insertGroup(organization);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java
index 82680222895..cbbf050e483 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java
@@ -21,12 +21,13 @@ package org.sonar.server.component.ws;
import com.google.common.collect.ImmutableSet;
import java.util.Objects;
-import java.util.Optional;
import java.util.Set;
+import javax.annotation.Nullable;
import org.sonar.api.resources.Qualifiers;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.project.Visibility;
import org.sonarqube.ws.Components;
@@ -46,7 +47,44 @@ class ComponentDtoToWsComponent {
// prevent instantiation
}
- static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, OrganizationDto organizationDto, Optional<SnapshotDto> lastAnalysis) {
+ static Components.Component.Builder projectOrAppToWsComponent(ProjectDto project, ComponentDto component, OrganizationDto organizationDto,
+ @Nullable SnapshotDto lastAnalysis) {
+
+ checkArgument(
+ Objects.equals(project.getOrganizationUuid(), organizationDto.getUuid()),
+ "OrganizationUuid (%s) of ComponentDto to convert to Ws Component is not the same as the one (%s) of the specified OrganizationDto",
+ project.getOrganizationUuid(), organizationDto.getUuid());
+
+ Components.Component.Builder wsComponent = Components.Component.newBuilder()
+ .setOrganization(organizationDto.getKey())
+ .setKey(project.getKey())
+ // TODO switch to using ProjectDto.getName() after fixing
+ // org.sonarqube.tests.project.ProjectInfoTest.project_name_and_description_should_be_truncated_if_too_long
+ .setName(component.name())
+ .setQualifier(project.getQualifier());
+
+ // TODO switch to using ProjectDto.getDescription() after fixing
+ // org.sonarqube.tests.project.ProjectInfoTest.project_name_and_description_should_be_truncated_if_too_long
+ ofNullable(emptyToNull(component.description())).ifPresent(wsComponent::setDescription);
+ ofNullable(emptyToNull(component.language())).ifPresent(wsComponent::setLanguage);
+ ofNullable(lastAnalysis).ifPresent(
+ analysis -> {
+ wsComponent.setAnalysisDate(formatDateTime(analysis.getCreatedAt()));
+ ofNullable(analysis.getPeriodDate()).ifPresent(leak -> wsComponent.setLeakPeriodDate(formatDateTime(leak)));
+ ofNullable(analysis.getProjectVersion()).ifPresent(wsComponent::setVersion);
+ });
+ if (QUALIFIERS_WITH_VISIBILITY.contains(project.getQualifier())) {
+ // TODO switch to using ProjectDto.isPrivate() instead after fixing UpdateVisibilityAction WS
+ wsComponent.setVisibility(Visibility.getLabel(component.isPrivate()));
+ if (Qualifiers.PROJECT.equals(project.getQualifier())) {
+ wsComponent.getTagsBuilder().addAllTags(project.getTags());
+ }
+ }
+
+ return wsComponent;
+ }
+
+ static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, OrganizationDto organizationDto, @Nullable SnapshotDto lastAnalysis) {
checkArgument(
Objects.equals(dto.getOrganizationUuid(), organizationDto.getUuid()),
"OrganizationUuid (%s) of ComponentDto to convert to Ws Component is not the same as the one (%s) of the specified OrganizationDto",
@@ -54,7 +92,7 @@ class ComponentDtoToWsComponent {
return componentDtoToWsComponent(dto, organizationDto.getKey(), lastAnalysis);
}
- private static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, String organizationDtoKey, Optional<SnapshotDto> lastAnalysis) {
+ private static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, String organizationDtoKey, @Nullable SnapshotDto lastAnalysis) {
Components.Component.Builder wsComponent = Components.Component.newBuilder()
.setOrganization(organizationDtoKey)
.setKey(dto.getKey())
@@ -65,8 +103,7 @@ class ComponentDtoToWsComponent {
ofNullable(emptyToNull(dto.path())).ifPresent(wsComponent::setPath);
ofNullable(emptyToNull(dto.description())).ifPresent(wsComponent::setDescription);
ofNullable(emptyToNull(dto.language())).ifPresent(wsComponent::setLanguage);
- setTags(dto, wsComponent);
- lastAnalysis.ifPresent(
+ ofNullable(lastAnalysis).ifPresent(
analysis -> {
wsComponent.setAnalysisDate(formatDateTime(analysis.getCreatedAt()));
ofNullable(analysis.getPeriodDate()).ifPresent(leak -> wsComponent.setLeakPeriodDate(formatDateTime(leak)));
@@ -77,10 +114,4 @@ class ComponentDtoToWsComponent {
}
return wsComponent;
}
-
- private static void setTags(ComponentDto dto, Components.Component.Builder wsComponent) {
- if (Qualifiers.PROJECT.equals(dto.qualifier())) {
- wsComponent.getTagsBuilder().addAllTags(dto.getTags());
- }
- }
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
index 67d15bfce07..abd37bdda48 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
@@ -24,6 +24,7 @@ import com.google.common.collect.Ordering;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -48,6 +49,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;
import org.sonar.server.component.ws.FilterParser.Criterion;
@@ -222,7 +224,7 @@ public class SearchProjectsAction implements ComponentsWsAction {
private SearchProjectsWsResponse handleForAnyOrganization(DbSession dbSession, SearchProjectsRequest request) {
SearchResults searchResults = searchData(dbSession, request, null);
- Set<String> organizationUuids = searchResults.projects.stream().map(ComponentDto::getOrganizationUuid).collect(toSet());
+ Set<String> organizationUuids = searchResults.projects.stream().map(ProjectDto::getOrganizationUuid).collect(toSet());
Map<String, OrganizationDto> organizationsByUuid = dbClient.organizationDao().selectByUuids(dbSession, organizationUuids)
.stream()
.collect(MoreCollectors.uniqueIndex(OrganizationDto::getUuid));
@@ -252,8 +254,8 @@ public class SearchProjectsAction implements ComponentsWsAction {
.setPage(request.getPage(), request.getPageSize()));
List<String> projectUuids = esResults.getIds();
- Ordering<ComponentDto> ordering = Ordering.explicit(projectUuids).onResultOf(ComponentDto::uuid);
- List<ComponentDto> projects = ordering.immutableSortedCopy(dbClient.componentDao().selectByUuids(dbSession, projectUuids));
+ Ordering<ProjectDto> ordering = Ordering.explicit(projectUuids).onResultOf(ProjectDto::getUuid);
+ List<ProjectDto> projects = ordering.immutableSortedCopy(dbClient.projectDao().selectByUuids(dbSession, new HashSet<>(projectUuids)));
Map<String, SnapshotDto> analysisByProjectUuid = getSnapshots(dbSession, request, projectUuids);
return new SearchResults(projects, favoriteProjectUuids, esResults, analysisByProjectUuid, query);
}
@@ -319,7 +321,7 @@ public class SearchProjectsAction implements ComponentsWsAction {
}
private SearchProjectsWsResponse buildResponse(SearchProjectsRequest request, SearchResults searchResults, Map<String, OrganizationDto> organizationsByUuid) {
- Function<ComponentDto, Component> dbToWsComponent = new DbToWsComponent(request, organizationsByUuid, searchResults.favoriteProjectUuids, searchResults.analysisByProjectUuid,
+ Function<ProjectDto, Component> dbToWsComponent = new DbToWsComponent(request, organizationsByUuid, searchResults.favoriteProjectUuids, searchResults.analysisByProjectUuid,
userSession.isLoggedIn());
Map<String, OrganizationDto> organizationsByUuidForAdditionalInfo = new HashMap<>();
@@ -426,7 +428,7 @@ public class SearchProjectsAction implements ComponentsWsAction {
}
}
- private static class DbToWsComponent implements Function<ComponentDto, Component> {
+ private static class DbToWsComponent implements Function<ProjectDto, Component> {
private final SearchProjectsRequest request;
private final Component.Builder wsComponent;
private final Map<String, OrganizationDto> organizationsByUuid;
@@ -445,19 +447,19 @@ public class SearchProjectsAction implements ComponentsWsAction {
}
@Override
- public Component apply(ComponentDto dbComponent) {
- String organizationUuid = dbComponent.getOrganizationUuid();
+ public Component apply(ProjectDto dbProject) {
+ String organizationUuid = dbProject.getOrganizationUuid();
OrganizationDto organizationDto = organizationsByUuid.get(organizationUuid);
checkFound(organizationDto, "Organization with uuid '%s' not found", organizationUuid);
wsComponent
.clear()
.setOrganization(organizationDto.getKey())
- .setKey(dbComponent.getDbKey())
- .setName(dbComponent.name())
- .setVisibility(Visibility.getLabel(dbComponent.isPrivate()));
- wsComponent.getTagsBuilder().addAllTags(dbComponent.getTags());
+ .setKey(dbProject.getKey())
+ .setName(dbProject.getName())
+ .setVisibility(Visibility.getLabel(dbProject.isPrivate()));
+ wsComponent.getTagsBuilder().addAllTags(dbProject.getTags());
- SnapshotDto snapshotDto = analysisByProjectUuid.get(dbComponent.uuid());
+ SnapshotDto snapshotDto = analysisByProjectUuid.get(dbProject.getUuid());
if (snapshotDto != null) {
if (request.getAdditionalFields().contains(ANALYSIS_DATE)) {
wsComponent.setAnalysisDate(formatDateTime(snapshotDto.getCreatedAt()));
@@ -468,7 +470,7 @@ public class SearchProjectsAction implements ComponentsWsAction {
}
if (isUserLoggedIn) {
- wsComponent.setIsFavorite(favoriteProjectUuids.contains(dbComponent.uuid()));
+ wsComponent.setIsFavorite(favoriteProjectUuids.contains(dbProject.getUuid()));
}
return wsComponent.build();
@@ -476,14 +478,14 @@ public class SearchProjectsAction implements ComponentsWsAction {
}
private static class SearchResults {
- private final List<ComponentDto> projects;
+ private final List<ProjectDto> projects;
private final Set<String> favoriteProjectUuids;
private final Facets facets;
private final Map<String, SnapshotDto> analysisByProjectUuid;
private final ProjectMeasuresQuery query;
private final int total;
- private SearchResults(List<ComponentDto> projects, Set<String> favoriteProjectUuids, SearchIdResult<String> searchResults, Map<String, SnapshotDto> analysisByProjectUuid,
+ private SearchResults(List<ProjectDto> projects, Set<String> favoriteProjectUuids, SearchIdResult<String> searchResults, Map<String, SnapshotDto> analysisByProjectUuid,
ProjectMeasuresQuery query) {
this.projects = projects;
this.favoriteProjectUuids = favoriteProjectUuids;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java
index 00433c15948..fdc5b24076c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java
@@ -19,11 +19,14 @@
*/
package org.sonar.server.component.ws;
+import com.google.common.collect.ImmutableSet;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import java.util.stream.IntStream;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
@@ -33,11 +36,14 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
+import org.sonarqube.ws.Components;
import org.sonarqube.ws.Components.ShowWsResponse;
import static org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent;
+import static org.sonar.server.component.ws.ComponentDtoToWsComponent.projectOrAppToWsComponent;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST;
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
@@ -48,6 +54,7 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SH
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT;
public class ShowAction implements ComponentsWsAction {
+ private static final Set<String> PROJECT_OR_APP_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.APP);
private final UserSession userSession;
private final DbClient dbClient;
private final ComponentFinder componentFinder;
@@ -103,7 +110,7 @@ public class ShowAction implements ComponentsWsAction {
Optional<SnapshotDto> lastAnalysis = dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, component.projectUuid());
List<ComponentDto> ancestors = dbClient.componentDao().selectAncestors(dbSession, component);
OrganizationDto organizationDto = componentFinder.getOrganization(dbSession, component);
- return buildResponse(component, organizationDto, ancestors, lastAnalysis);
+ return buildResponse(dbClient, dbSession, component, organizationDto, ancestors, lastAnalysis.orElse(null));
}
}
@@ -115,15 +122,37 @@ public class ShowAction implements ComponentsWsAction {
return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest);
}
- private static ShowWsResponse buildResponse(ComponentDto component, OrganizationDto organizationDto, List<ComponentDto> orderedAncestors, Optional<SnapshotDto> lastAnalysis) {
+ private static ShowWsResponse buildResponse(DbClient dbClient, DbSession dbSession, ComponentDto component,
+ OrganizationDto organizationDto, List<ComponentDto> orderedAncestors,
+ @Nullable SnapshotDto lastAnalysis) {
ShowWsResponse.Builder response = ShowWsResponse.newBuilder();
- response.setComponent(componentDtoToWsComponent(component, organizationDto, lastAnalysis));
+ response.setComponent(toWsComponent(dbClient, dbSession, component, organizationDto, lastAnalysis));
+ addAncestorsToResponse(dbClient, dbSession, response, orderedAncestors, organizationDto, lastAnalysis);
+ return response.build();
+ }
+ private static void addAncestorsToResponse(DbClient dbClient, DbSession dbSession, ShowWsResponse.Builder response, List<ComponentDto> orderedAncestors,
+ OrganizationDto organizationDto,
+ @Nullable SnapshotDto lastAnalysis) {
// ancestors are ordered from root to leaf, whereas it's the opposite in WS response
int size = orderedAncestors.size() - 1;
IntStream.rangeClosed(0, size).forEach(
- index -> response.addAncestors(componentDtoToWsComponent(orderedAncestors.get(size - index), organizationDto, lastAnalysis)));
- return response.build();
+ index -> response.addAncestors(toWsComponent(dbClient, dbSession, orderedAncestors.get(size - index), organizationDto, lastAnalysis)));
+ }
+
+ private static Components.Component.Builder toWsComponent(DbClient dbClient, DbSession dbSession, ComponentDto component, OrganizationDto organizationDto,
+ @Nullable SnapshotDto lastAnalysis) {
+ if (isProjectOrApp(component)) {
+ ProjectDto project = dbClient.projectDao().selectProjectOrAppByKey(dbSession, component.getKey())
+ .orElseThrow(() -> new IllegalStateException("Project is in invalid state."));
+ return projectOrAppToWsComponent(project, component, organizationDto, lastAnalysis);
+ } else {
+ return componentDtoToWsComponent(component, organizationDto, lastAnalysis);
+ }
+ }
+
+ private static boolean isProjectOrApp(ComponentDto component) {
+ return component.getMainBranchProjectUuid() == null && PROJECT_OR_APP_QUALIFIERS.contains(component.qualifier());
}
private static Request toShowWsRequest(org.sonar.api.server.ws.Request request) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java
index ece7f0cbd4a..c99626bda3d 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/TreeAction.java
@@ -29,10 +29,10 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Response;
@@ -48,6 +48,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTreeQuery;
import org.sonar.db.component.ComponentTreeQuery.Strategy;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Components;
@@ -61,6 +62,7 @@ import static org.sonar.core.util.stream.MoreCollectors.toList;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.CHILDREN;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES;
import static org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent;
+import static org.sonar.server.component.ws.ComponentDtoToWsComponent.projectOrAppToWsComponent;
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
@@ -97,6 +99,8 @@ public class TreeAction implements ComponentsWsAction {
private final UserSession userSession;
private final I18n i18n;
+ private static final Set<String> PROJECT_OR_APP_QUALIFIERS = ImmutableSortedSet.of(Qualifiers.PROJECT, Qualifiers.APP);
+
public TreeAction(DbClient dbClient, ComponentFinder componentFinder, ResourceTypes resourceTypes, UserSession userSession, I18n i18n) {
this.dbClient = dbClient;
this.componentFinder = componentFinder;
@@ -182,7 +186,7 @@ public class TreeAction implements ComponentsWsAction {
Map<String, ComponentDto> referenceComponentsByUuid = searchReferenceComponentsByUuid(dbSession, components);
- return buildResponse(baseComponent, organizationDto, components, referenceComponentsByUuid,
+ return buildResponse(dbSession, baseComponent, organizationDto, components, referenceComponentsByUuid,
Paging.forPageIndex(treeRequest.getPage()).withPageSize(treeRequest.getPageSize()).andTotal(total));
}
}
@@ -211,7 +215,7 @@ public class TreeAction implements ComponentsWsAction {
userSession.checkComponentPermission(UserRole.USER, baseComponent);
}
- private static TreeWsResponse buildResponse(ComponentDto baseComponent, OrganizationDto organizationDto, List<ComponentDto> components,
+ private TreeWsResponse buildResponse(DbSession dbSession, ComponentDto baseComponent, OrganizationDto organizationDto, List<ComponentDto> components,
Map<String, ComponentDto> referenceComponentsByUuid, Paging paging) {
TreeWsResponse.Builder response = TreeWsResponse.newBuilder();
response.getPagingBuilder()
@@ -220,17 +224,25 @@ public class TreeAction implements ComponentsWsAction {
.setTotal(paging.total())
.build();
- response.setBaseComponent(toWsComponent(baseComponent, organizationDto, referenceComponentsByUuid));
+ response.setBaseComponent(toWsComponent(dbSession, baseComponent, organizationDto, referenceComponentsByUuid));
for (ComponentDto dto : components) {
- response.addComponents(toWsComponent(dto, organizationDto, referenceComponentsByUuid));
+ response.addComponents(toWsComponent(dbSession, dto, organizationDto, referenceComponentsByUuid));
}
return response.build();
}
- private static Components.Component.Builder toWsComponent(ComponentDto component, OrganizationDto organizationDto,
+ private Components.Component.Builder toWsComponent(DbSession dbSession, ComponentDto component, OrganizationDto organizationDto,
Map<String, ComponentDto> referenceComponentsByUuid) {
- Components.Component.Builder wsComponent = componentDtoToWsComponent(component, organizationDto, Optional.empty());
+
+ Components.Component.Builder wsComponent;
+ if (component.getMainBranchProjectUuid() == null && component.isRootProject() &&
+ PROJECT_OR_APP_QUALIFIERS.contains(component.qualifier())) {
+ ProjectDto projectDto = componentFinder.getProjectOrApplicationByKey(dbSession, component.getKey());
+ wsComponent = projectOrAppToWsComponent(projectDto, component, organizationDto, null);
+ } else {
+ wsComponent = componentDtoToWsComponent(component, organizationDto, null);
+ }
ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid());
if (referenceComponent != null) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projecttag/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projecttag/ws/SetAction.java
index 79bbc3458bf..01079802a0a 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projecttag/ws/SetAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projecttag/ws/SetAction.java
@@ -98,15 +98,11 @@ public class SetAction implements ProjectTagsWsAction {
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
userSession.checkProjectPermission(UserRole.ADMIN, project);
- ComponentDto component = componentFinder.getByKey(dbSession, projectKey);
-
project.setTags(tags);
project.setUpdatedAt(system2.now());
dbClient.projectDao().updateTags(dbSession, project);
// FIXME we use the old table to index and also when returning generic components, so we still need to add it to the old table.
- component.setTags(tags);
- dbClient.componentDao().updateTags(dbSession, component);
projectIndexers.commitAndIndexProjects(dbSession, singletonList(project), PROJECT_TAGS_UPDATE);
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java
index 0e49a09b093..d7dddab5a5a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java
@@ -326,7 +326,7 @@ public class ActivityActionTest {
@Test
public void search_activity_returns_application() {
- ComponentDto apacheApp = db.components().insertApplication(db.getDefaultOrganization(), a -> a.setName("Apache App"));
+ ComponentDto apacheApp = db.components().insertPublicApplication(db.getDefaultOrganization(), a -> a.setName("Apache App"));
db.components().insertSnapshot(apacheApp);
logInAsSystemAdministrator();
insertActivity("T2", apacheApp, SUCCESS);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/AnalysisStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/AnalysisStatusActionTest.java
index af85b110726..83580d02c46 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/AnalysisStatusActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/AnalysisStatusActionTest.java
@@ -30,7 +30,6 @@ import org.sonar.db.DbTester;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskMessageDto;
-import org.sonar.db.component.BranchDao;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
@@ -100,11 +99,11 @@ public class AnalysisStatusActionTest {
public void json_example() {
OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org-1"));
ComponentDto project = db.components().insertPrivateProject(organization,
- p -> p.setUuid("AU_w74XMgAS1Hm6h4-Y-"),
- p -> p.setProjectUuid("AU_w74XMgAS1Hm6h4-Y-"),
- p -> p.setRootUuid("AU_w74XMgAS1Hm6h4-Y-"),
- p -> p.setDbKey("com.github.kevinsawicki:http-request-parent"),
- p -> p.setName("HttpRequest"));
+ p -> p.setUuid("AU_w74XMgAS1Hm6h4-Y-")
+ .setProjectUuid("AU_w74XMgAS1Hm6h4-Y-")
+ .setRootUuid("AU_w74XMgAS1Hm6h4-Y-")
+ .setDbKey("com.github.kevinsawicki:http-request-parent")
+ .setName("HttpRequest"));
userSession.addProjectPermission(UserRole.USER, project);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
index ffa9529b3ca..18772de9c9c 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
@@ -165,8 +165,7 @@ public class ComponentServiceUpdateKeyTest {
assertComponentKeyUpdated(inactiveModule.getDbKey(), "your_project:root:inactive_module");
assertComponentKeyUpdated(inactiveFile.getDbKey(), "your_project:root:module:src/InactiveFile.xoo");
verify(projectLifeCycleListeners).onProjectsRekeyed(ImmutableSet.of(
- new RekeyedProject(new Project(project.uuid(), "your_project", project.name(), project.uuid(), emptyList()), "my_project")
- ));
+ new RekeyedProject(new Project(project.uuid(), "your_project", project.name(), project.uuid(), emptyList()), "my_project")));
}
@Test
@@ -182,8 +181,7 @@ public class ComponentServiceUpdateKeyTest {
assertComponentKeyUpdated(module.getDbKey(), "your_project:root:module");
assertComponentKeyUpdated(file.getDbKey(), "your_project:root:module:src/File.xoo");
verify(projectLifeCycleListeners).onProjectsRekeyed(ImmutableSet.of(
- new RekeyedProject(new Project(project.uuid(), "your_project", project.name(), project.uuid(), emptyList()), "my_project")
- ));
+ new RekeyedProject(new Project(project.uuid(), "your_project", project.name(), project.uuid(), emptyList()), "my_project")));
}
private void assertComponentKeyUpdated(String oldKey, String newKey) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ComponentDtoToWsComponentTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ComponentDtoToWsComponentTest.java
index 4e458088d07..a757fb4f8e3 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ComponentDtoToWsComponentTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ComponentDtoToWsComponentTest.java
@@ -44,7 +44,7 @@ public class ComponentDtoToWsComponentTest {
expectedException.expectMessage("OrganizationUuid (" + organizationDto1.getUuid() + ") of ComponentDto to convert " +
"to Ws Component is not the same as the one (" + organizationDto2.getUuid() + ") of the specified OrganizationDto");
- componentDtoToWsComponent(componentDto, organizationDto2, Optional.empty());
+ componentDtoToWsComponent(componentDto, organizationDto2, null);
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
index a7b562ee6d3..857ee247684 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
@@ -45,6 +45,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder;
import org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest;
@@ -201,19 +202,16 @@ public class SearchProjectsActionTest {
OrganizationDto organization2Dto = db.organizations().insert(dto -> dto.setKey("my-org-key-2").setName("Bar"));
MetricDto coverage = db.measures().insertMetric(c -> c.setKey(COVERAGE).setValueType("PERCENT"));
- ComponentDto project1 = insertProject(organization1Dto, c -> c
- .setDbKey(KEY_PROJECT_EXAMPLE_001)
- .setName("My Project 1")
- .setTagsString("finance, java"),
+ ComponentDto project1 = insertProject(organization1Dto,
+ c -> c.setDbKey(KEY_PROJECT_EXAMPLE_001).setName("My Project 1"),
+ p -> p.setTagsString("finance, java"),
new Measure(coverage, c -> c.setValue(80d)));
- ComponentDto project2 = insertProject(organization1Dto, c -> c
- .setDbKey(KEY_PROJECT_EXAMPLE_002)
- .setName("My Project 2"),
+ ComponentDto project2 = insertProject(organization1Dto,
+ c -> c.setDbKey(KEY_PROJECT_EXAMPLE_002).setName("My Project 2"),
new Measure(coverage, c -> c.setValue(90d)));
- ComponentDto project3 = insertProject(organization2Dto, c -> c
- .setDbKey(KEY_PROJECT_EXAMPLE_003)
- .setName("My Project 3")
- .setTagsString("sales, offshore, java"),
+ ComponentDto project3 = insertProject(organization2Dto,
+ c -> c.setDbKey(KEY_PROJECT_EXAMPLE_003).setName("My Project 3"),
+ p -> p.setTagsString("sales, offshore, java"),
new Measure(coverage, c -> c.setValue(20d)));
addFavourite(project1);
@@ -372,9 +370,9 @@ public class SearchProjectsActionTest {
userSession.logIn();
OrganizationDto organizationDto = db.organizations().insert();
MetricDto ratingMetric = db.measures().insertMetric(c -> c.setKey(newMetricKey).setValueType(INT.name()));
- ComponentDto project1 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(1d)));
+ insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(1d)));
ComponentDto project2 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(2d)));
- ComponentDto project3 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(3d)));
+ insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(3d)));
SearchProjectsWsResponse result = call(request.setFilter(newMetricKey + " = 2"));
@@ -385,9 +383,9 @@ public class SearchProjectsActionTest {
public void filter_projects_by_tags() {
userSession.logIn();
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project1 = insertProject(organizationDto, c -> c.setTags(asList("finance", "platform")));
- ComponentDto project2 = insertProject(organizationDto, c -> c.setTags(singletonList("marketing")));
- ComponentDto project3 = insertProject(organizationDto, c -> c.setTags(singletonList("offshore")));
+ ComponentDto project1 = insertProject(organizationDto, defaults(), p -> p.setTags(asList("finance", "platform")));
+ insertProject(organizationDto, defaults(), p -> p.setTags(singletonList("marketing")));
+ ComponentDto project3 = insertProject(organizationDto, defaults(), p -> p.setTags(singletonList("offshore")));
SearchProjectsWsResponse result = call(request.setFilter("tags in (finance, offshore)"));
@@ -704,9 +702,9 @@ public class SearchProjectsActionTest {
public void return_tags_facet() {
userSession.logIn();
OrganizationDto organization = db.getDefaultOrganization();
- insertProject(organization, c -> c.setTags(asList("finance", "platform")));
- insertProject(organization, c -> c.setTags(singletonList("offshore")));
- insertProject(organization, c -> c.setTags(singletonList("offshore")));
+ insertProject(organization, defaults(), p -> p.setTags(asList("finance", "platform")));
+ insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore")));
+ insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore")));
SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_TAGS)));
@@ -725,9 +723,9 @@ public class SearchProjectsActionTest {
public void return_tags_facet_with_tags_having_no_project_if_tags_is_in_filter() {
userSession.logIn();
OrganizationDto organization = db.getDefaultOrganization();
- insertProject(organization, c -> c.setTags(asList("finance", "platform")));
- insertProject(organization, c -> c.setTags(singletonList("offshore")));
- insertProject(organization, c -> c.setTags(singletonList("offshore")));
+ insertProject(organization, defaults(), p -> p.setTags(asList("finance", "platform")));
+ insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore")));
+ insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore")));
SearchProjectsWsResponse result = call(request.setFilter("tags = marketing").setFacets(singletonList(FILTER_TAGS)));
@@ -1182,12 +1180,16 @@ public class SearchProjectsActionTest {
}
private ComponentDto insertProject(OrganizationDto organizationDto, Measure... measures) {
- return insertProject(organizationDto, c -> {
- }, measures);
+ return insertProject(organizationDto, defaults(), defaults(), measures);
}
- private ComponentDto insertProject(OrganizationDto organizationDto, Consumer<ComponentDto> projectConsumer, Measure... measures) {
- ComponentDto project = db.components().insertPublicProject(organizationDto, projectConsumer);
+ private ComponentDto insertProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentConsumer, Measure... measures) {
+ return insertProject(organizationDto, componentConsumer, defaults(), measures);
+ }
+
+ private ComponentDto insertProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentConsumer, Consumer<ProjectDto> projectConsumer,
+ Measure... measures) {
+ ComponentDto project = db.components().insertPublicProject(organizationDto, componentConsumer, projectConsumer);
Arrays.stream(measures).forEach(m -> db.measures().insertLiveMeasure(project, m.metric, m.consumer));
authorizationIndexerTester.allowOnlyAnyone(project);
projectMeasuresIndexer.indexOnAnalysis(project.uuid());
@@ -1203,4 +1205,9 @@ public class SearchProjectsActionTest {
this.consumer = consumer;
}
}
+
+ private static <T> Consumer<T> defaults() {
+ return t -> {
+ };
+ }
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
index 477c0bfe876..5ef8be8d16a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
@@ -381,12 +381,14 @@ public class ShowActionTest {
private void insertJsonExampleComponentsAndSnapshots() {
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-1");
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "AVIF98jgA3Ax6PH2efOW")
- .setDbKey("com.sonarsource:java-markdown")
- .setName("Java Markdown")
- .setDescription("Java Markdown Project")
- .setQualifier(Qualifiers.PROJECT)
- .setTagsString("language, plugin"));
+ ComponentDto project = db.components().insertPrivateProject(organizationDto,
+ c -> c.setUuid("AVIF98jgA3Ax6PH2efOW")
+ .setProjectUuid("AVIF98jgA3Ax6PH2efOW")
+ .setDbKey("com.sonarsource:java-markdown")
+ .setName("Java Markdown")
+ .setDescription("Java Markdown Project")
+ .setQualifier(Qualifiers.PROJECT),
+ p -> p.setTagsString("language, plugin"));
db.components().insertSnapshot(project, snapshot -> snapshot
.setProjectVersion("1.1")
.setCreatedAt(parseDateTime("2017-03-01T11:39:03+0100").getTime())
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
index 0fc26582443..67729fcf944 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
@@ -584,7 +584,7 @@ public class SuggestionsActionTest {
public void should_only_provide_project_for_certain_qualifiers() {
String query = randomAlphabetic(10);
- ComponentDto app = db.components().insertApplication(organization, v -> v.setName(query));
+ ComponentDto app = db.components().insertPublicApplication(organization, v -> v.setName(query));
ComponentDto view = db.components().insertView(organization, v -> v.setName(query));
ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubView(view).setName(query));
ComponentDto project = db.components().insertPrivateProject(organization, p -> p.setName(query));
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
index 830792ef4a0..8bdfc865fc5 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
@@ -300,7 +300,7 @@ public class TreeActionTest {
@Test
public void response_is_empty_on_provisioned_projects() {
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization(), "project-uuid");
logInWithBrowsePermission(project);
TreeWsResponse response = ws.newRequest()
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java
index 2e98ebe35ec..e61776b8b6a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java
@@ -505,7 +505,7 @@ public class SearchActionComponentsTest {
@Test
public void ignore_application_without_browse_permission() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization());
db.components().insertComponents(newProjectCopy("PC1", project, application));
RuleDefinitionDto rule = db.rules().insertIssueRule();
db.issues().insertIssue(rule, project, project);
@@ -522,7 +522,7 @@ public class SearchActionComponentsTest {
@Test
public void search_application_without_projects() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization());
RuleDefinitionDto rule = db.rules().insertIssueRule();
db.issues().insertIssue(rule, project, project);
allowAnyoneOnProjects(project, application);
@@ -539,7 +539,7 @@ public class SearchActionComponentsTest {
public void search_by_application_and_by_leak() {
Date now = new Date();
RuleDefinitionDto rule = db.rules().insertIssueRule();
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization());
// Project 1
ComponentDto project1 = db.components().insertPublicProject();
db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
@@ -570,7 +570,7 @@ public class SearchActionComponentsTest {
public void search_by_application_and_project() {
ComponentDto project1 = db.components().insertPublicProject();
ComponentDto project2 = db.components().insertPublicProject();
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization());
db.components().insertComponents(newProjectCopy("PC1", project1, application));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
RuleDefinitionDto rule = db.rules().insertIssueRule();
@@ -593,7 +593,7 @@ public class SearchActionComponentsTest {
public void search_by_application_and_project_and_leak() {
Date now = new Date();
RuleDefinitionDto rule = db.rules().insertIssueRule();
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization());
// Project 1
ComponentDto project1 = db.components().insertPublicProject();
db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
@@ -625,7 +625,7 @@ public class SearchActionComponentsTest {
public void search_by_application_and_by_leak_when_one_project_has_no_leak() {
Date now = new Date();
RuleDefinitionDto rule = db.rules().insertIssueRule();
- ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization());
// Project 1
ComponentDto project1 = db.components().insertPublicProject();
db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java
index 6cd046cfaf8..ebab1802102 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java
@@ -356,7 +356,7 @@ public class PermissionTemplateServiceTest {
@Test
public void apply_template_on_applications() {
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto application = dbTester.components().insertApplication(organization);
+ ComponentDto application = dbTester.components().insertPublicApplication(organization);
PermissionTemplateDto permissionTemplate = dbTester.permissionTemplates().insertTemplate(organization);
GroupDto group = dbTester.users().insertGroup(organization);
dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, group, ADMINISTER.getKey());
@@ -372,7 +372,7 @@ public class PermissionTemplateServiceTest {
@Test
public void apply_default_view_template_on_application() {
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto application = dbTester.components().insertApplication(organization);
+ ComponentDto application = dbTester.components().insertPublicApplication(organization);
PermissionTemplateDto projectPermissionTemplate = dbTester.permissionTemplates().insertTemplate(organization);
PermissionTemplateDto appPermissionTemplate = dbTester.permissionTemplates().insertTemplate(organization);
PermissionTemplateDto portPermissionTemplate = dbTester.permissionTemplates().insertTemplate(organization);
@@ -390,7 +390,7 @@ public class PermissionTemplateServiceTest {
@Test
public void apply_project_default_template_on_application_when_no_application_default_template() {
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto application = dbTester.components().insertApplication(organization);
+ ComponentDto application = dbTester.components().insertPublicApplication(organization);
PermissionTemplateDto projectPermissionTemplate = dbTester.permissionTemplates().insertTemplate(organization);
GroupDto group = dbTester.users().insertGroup(organization);
dbTester.permissionTemplates().addGroupToTemplate(projectPermissionTemplate, group, PROVISION_PROJECTS.getKey());
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java
index 5c758f2ffc5..376367673da 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java
@@ -31,7 +31,6 @@ import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.ComponentService;
import org.sonar.server.es.ProjectIndexers;
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
index 7a0a3a67b67..3eb08cff46b 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
@@ -204,7 +204,7 @@ public class UpdateVisibilityActionTest {
ComponentDto dir = ComponentTesting.newDirectory(project, "path");
ComponentDto file = ComponentTesting.newFileDto(project);
dbTester.components().insertComponents(module, dir, file);
- ComponentDto application = dbTester.components().insertApplication(organization);
+ ComponentDto application = dbTester.components().insertPublicApplication(organization);
ComponentDto portfolio = dbTester.components().insertView(organization);
ComponentDto subView = ComponentTesting.newSubView(portfolio);
ComponentDto projectCopy = newProjectCopy("foo", project, subView);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java
index 559446651e2..45ceef49382 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java
@@ -234,7 +234,7 @@ public class SearchActionTest {
@Test
public void return_analyses_of_application() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto application = db.components().insertApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication(organization);
userSession.registerComponents(application);
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
SnapshotDto secondAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(2_000_000L));
@@ -254,7 +254,7 @@ public class SearchActionTest {
@Test
public void return_definition_change_events_on_application_analyses() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto application = db.components().insertApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication(organization);
userSession.registerComponents(application);
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
@@ -280,7 +280,7 @@ public class SearchActionTest {
@UseDataProvider("changedBranches")
public void application_definition_change_with_branch(@Nullable String oldBranch, @Nullable String newBranch) {
OrganizationDto organization = db.organizations().insert();
- ComponentDto application = db.components().insertApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication(organization);
userSession.registerComponents(application);
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
@@ -303,7 +303,7 @@ public class SearchActionTest {
@Test
public void incorrect_eventcomponentchange_two_identical_changes_added_on_same_project() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto application = db.components().insertApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication(organization);
userSession.registerComponents(application);
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
@@ -333,7 +333,7 @@ public class SearchActionTest {
@Test
public void incorrect_eventcomponentchange_incorrect_category() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto application = db.components().insertApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication(organization);
userSession.registerComponents(application);
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
@@ -360,7 +360,7 @@ public class SearchActionTest {
@Test
public void incorrect_eventcomponentchange_three_component_changes_on_same_project() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto application = db.components().insertApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication(organization);
userSession.registerComponents(application);
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
@@ -392,7 +392,7 @@ public class SearchActionTest {
@Test
public void incorrect_quality_gate_information() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto application = db.components().insertApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication(organization);
userSession.registerComponents(application);
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java
index ce6a8eacc56..0c1df5d6d79 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java
@@ -83,7 +83,8 @@ public class SetActionTest {
@Test
public void reset_tags() {
- project = db.components().insertPrivateProjectDto(p -> p.setTagsString("platform,scanner"));
+ project = db.components().insertPrivateProjectDto(c -> {
+ }, p -> p.setTagsString("platform,scanner"));
call(project.getKey(), "");
@@ -92,7 +93,7 @@ public class SetActionTest {
@Test
public void override_existing_tags() {
- project = db.components().insertPrivateProjectDto(p -> p.setTagsString("marketing,languages"));
+ project = db.components().insertPrivateProjectDto(c -> {}, p -> p.setTagsString("marketing,languages"));
call(project.getKey(), "finance,offshore,platform");
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
index ea329c28ac8..0583bd29652 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
@@ -196,7 +196,7 @@ public class ComponentActionTest {
public void return_component_info_when_file_on_master() {
OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org2"));
db.qualityGates().createDefaultQualityGate(organization);
- ComponentDto main = componentDbTester.insertPrivateProject(organization, p -> p.setName("Sample"), p -> p.setDbKey("sample"));
+ ComponentDto main = componentDbTester.insertPrivateProject(organization, p -> p.setName("Sample").setDbKey("sample"));
userSession.addProjectPermission(UserRole.USER, main);
init();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java
index 49286534145..45388da735e 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java
@@ -213,7 +213,7 @@ public class CurrentActionTest {
@Test
public void json_example() {
- ComponentDto componentDto = db.components().insertPrivateProject(u -> u.setUuid("UUID-of-the-death-star"), u -> u.setDbKey("death-star-key"));
+ ComponentDto componentDto = db.components().insertPrivateProject(u -> u.setUuid("UUID-of-the-death-star").setDbKey("death-star-key"));
UserDto obiwan = db.users().insertUser(user -> user
.setLogin("obiwan.kenobi")
.setName("Obiwan Kenobi")