aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBelen Pruvost <belen.pruvost@sonarsource.com>2021-08-17 13:57:09 +0200
committersonartech <sonartech@sonarsource.com>2021-08-19 20:08:15 +0000
commit7f6c8882fb5117beb4a6c092c8c280f5c782c1e1 (patch)
tree28d2f67bebe2464a3d80a26c17e571f058472f8a
parent6684e2cb53b81ae3522c18efa2fe2f9d44bec5e9 (diff)
downloadsonarqube-7f6c8882fb5117beb4a6c092c8c280f5c782c1e1.tar.gz
sonarqube-7f6c8882fb5117beb4a6c092c8c280f5c782c1e1.zip
SONAR-15142 - Skip visibility update logs from PersistComponentsStep
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java9
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java50
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java2
4 files changed, 36 insertions, 27 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
index 9bc638abd88..ea34d448ac6 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
@@ -143,7 +143,7 @@ public class PersistComponentsStep implements ComputationStep {
} else if (type == Component.Type.VIEW) {
qualifier = VIEW;
}
- dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, projectUuid, isRootPrivate, qualifier, componentName);
+ dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, projectUuid, isRootPrivate, qualifier, componentName, false);
}
private static boolean isRootPrivate(Component root, Map<String, ComponentDto> existingDtosByUuids) {
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 5a7605eab04..110bd365e05 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
@@ -40,6 +40,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.model.ComponentNewValue;
+
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Collections.emptyList;
import static org.sonar.core.util.stream.MoreCollectors.toList;
@@ -278,9 +279,9 @@ public class ComponentDao implements Dao {
/**
* Selects all components that are relevant for indexing. The result is not returned (since it is usually too big), but handed over to the <code>handler</code>
*
- * @param session the database session
+ * @param session the database session
* @param projectUuid the project uuid, which is selected with all of its children
- * @param handler the action to be applied to every result
+ * @param handler the action to be applied to every result
*/
public void scrollForIndexing(DbSession session, @Nullable String projectUuid, ResultHandler<ComponentDto> handler) {
mapper(session).scrollForIndexing(projectUuid, handler);
@@ -376,8 +377,8 @@ public class ComponentDao implements Dao {
}
public void setPrivateForRootComponentUuid(DbSession session, String projectUuid, boolean isPrivate,
- @Nullable String qualifier, String componentName) {
- if(auditPersister != null) {
+ @Nullable String qualifier, String componentName, boolean track) {
+ if (track && auditPersister != null) {
ComponentNewValue componentNewValue = new ComponentNewValue(projectUuid, componentName, isPrivate, qualifier);
auditPersister.updateComponentVisibility(session, componentNewValue, qualifier);
}
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 be9a2c339f8..411cdb3ec52 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
@@ -23,6 +23,21 @@ import com.google.common.collect.ImmutableMap;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+import javax.annotation.Nullable;
import org.assertj.core.api.ListAssert;
import org.junit.Rule;
import org.junit.Test;
@@ -60,6 +75,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
import static org.sonar.api.issue.Issue.STATUS_CLOSED;
import static org.sonar.api.issue.Issue.STATUS_CONFIRMED;
import static org.sonar.api.issue.Issue.STATUS_OPEN;
@@ -75,27 +91,12 @@ import static org.sonar.db.component.ComponentTesting.newBranchDto;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
+import static org.sonar.db.component.ComponentTesting.newPortfolio;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
-import static org.sonar.db.component.ComponentTesting.newPortfolio;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.CHILDREN;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES;
-import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Random;
-import java.util.Set;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
@RunWith(DataProviderRunner.class)
public class ComponentDaoTest {
@@ -1771,7 +1772,7 @@ public class ComponentDaoTest {
db.components().insertComponent(newPrivateProjectDto().setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(),
};
- underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, true, null, "name");
+ underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, true, null, "name", true);
assertThat(privateFlagOfUuid(uuids[0])).isTrue();
assertThat(privateFlagOfUuid(uuids[1])).isTrue();
@@ -1779,7 +1780,7 @@ public class ComponentDaoTest {
assertThat(privateFlagOfUuid(uuids[3])).isFalse();
assertThat(privateFlagOfUuid(uuids[4])).isFalse();
- underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, false, null, "name");
+ underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, false, null, "name", true);
assertThat(privateFlagOfUuid(uuids[0])).isFalse();
assertThat(privateFlagOfUuid(uuids[1])).isFalse();
@@ -1787,7 +1788,7 @@ public class ComponentDaoTest {
assertThat(privateFlagOfUuid(uuids[3])).isFalse();
assertThat(privateFlagOfUuid(uuids[4])).isFalse();
- underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, false, null, "name");
+ underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, false, null, "name", true);
assertThat(privateFlagOfUuid(uuids[0])).isFalse();
assertThat(privateFlagOfUuid(uuids[1])).isFalse();
@@ -1795,7 +1796,7 @@ public class ComponentDaoTest {
assertThat(privateFlagOfUuid(uuids[3])).isFalse();
assertThat(privateFlagOfUuid(uuids[4])).isFalse();
- underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, true, null, "name");
+ underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, true, null, "name", true);
assertThat(privateFlagOfUuid(uuids[0])).isFalse();
assertThat(privateFlagOfUuid(uuids[1])).isFalse();
@@ -1883,13 +1884,20 @@ public class ComponentDaoTest {
@Test
public void setPrivateForRootComponentUuid_auditPersisterIsCalled() {
- underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, APP, "appName");
+ underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, APP, "appName", true);
verify(auditPersister, Mockito.times(1))
.updateComponentVisibility(any(DbSession.class), any(ComponentNewValue.class), anyString());
}
@Test
+ public void setPrivateForRootComponentUuid_withoutTrack_auditPersisterIsNotCalled() {
+ underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, APP, "appName", false);
+
+ verifyNoInteractions(auditPersister);
+ }
+
+ @Test
public void update_auditPersisterIsCalled() {
ComponentUpdateDto app = new ComponentUpdateDto();
app.setBQualifier(APP);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
index c860f8b9981..9a79790f69c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
@@ -135,7 +135,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
private void setPrivateForRootComponentUuid(DbSession dbSession, ComponentDto component, boolean isPrivate) {
String uuid = component.uuid();
- dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.qualifier(), component.name());
+ dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.qualifier(), component.name(), true);
if (component.qualifier().equals(Qualifiers.PROJECT) || component.qualifier().equals(Qualifiers.APP)) {
dbClient.projectDao().updateVisibility(dbSession, uuid, isPrivate);