import org.sonar.db.Pagination;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.NoOpAuditPersister;
+import org.sonar.db.audit.model.ProjectNewValue;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@Test
void insert_withTrack_shouldCallAuditPersister() {
- ProjectDto dto1 = createProject("o1", "p1");
+ var dto1 = createProject("o1", "p1").setAiCodeFixEnabled(true);
projectDaoWithAuditPersister.insert(db.getSession(), dto1, true);
- verify(auditPersister, times(1)).addComponent(any(), any());
+ verify(auditPersister, times(1)).addComponent(any(),
+ argThat(componentNewValue -> ((ProjectNewValue) componentNewValue).isAiCodeFixEnabled()));
}
@Test
void update_shouldCallAuditPersister() {
- ProjectDto dto1 = createProject("o1", "p1");
+ var dto1 = createProject("o1", "p1").setAiCodeFixEnabled(true);
projectDaoWithAuditPersister.update(db.getSession(), dto1);
- verify(auditPersister, times(1)).updateComponent(any(), any());
+ verify(auditPersister, times(1)).updateComponent(any(),
+ argThat(componentNewValue -> ((ProjectNewValue) componentNewValue).isAiCodeFixEnabled()));
}
@Test
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.project.ProjectDto;
import static java.util.Objects.requireNonNull;
private Boolean isEnabled;
private String path;
- public ComponentNewValue(ProjectDto project) {
- this(project.getUuid(), project.getName(), project.getKey(), project.isPrivate(), project.getDescription(), project.getQualifier());
- }
-
public ComponentNewValue(ComponentDto component) {
this(component.uuid(), component.name(), component.getKey(), component.isPrivate(), component.description(), component.qualifier());
}
this(uuid, name, key, isPrivate, description, qualifier);
}
- private ComponentNewValue(String uuid, String name, String key, @Nullable Boolean isPrivate, @Nullable String description, String qualifier) {
+ ComponentNewValue(String uuid, String name, String key, @Nullable Boolean isPrivate, @Nullable String description, String qualifier) {
this.componentUuid = requireNonNull(uuid);
this.componentName = name;
this.componentKey = key;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.audit.model;
+
+import java.util.Objects;
+import org.sonar.db.project.ProjectDto;
+
+public class ProjectNewValue extends ComponentNewValue {
+
+ private final boolean aiCodeFixEnabled;
+
+ public ProjectNewValue(ProjectDto project) {
+ super(project.getUuid(), project.getName(), project.getKey(), Boolean.valueOf(project.isPrivate()), project.getDescription(), project.getQualifier());
+ this.aiCodeFixEnabled = project.getAiCodeFixEnabled();
+ }
+
+ @Override
+ public String toString() {
+ var sb = new StringBuilder(super.toString());
+ var length = sb.length();
+ sb.replace(length - 1, length, ", ");
+ addField(sb, "\"aiCodeFixEnabled\": ", Objects.toString(this.aiCodeFixEnabled, "false"), false);
+ endString(sb);
+
+ return sb.toString();
+ }
+
+ public boolean isAiCodeFixEnabled() {
+ return aiCodeFixEnabled;
+ }
+}
import org.sonar.db.DbSession;
import org.sonar.db.Pagination;
import org.sonar.db.audit.AuditPersister;
-import org.sonar.db.audit.model.ComponentNewValue;
+import org.sonar.db.audit.model.ProjectNewValue;
import static java.util.Collections.emptyList;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public void insert(DbSession session, ProjectDto project, boolean track) {
if (track) {
- auditPersister.addComponent(session, new ComponentNewValue(project));
+ auditPersister.addComponent(session, new ProjectNewValue(project));
}
mapper(session).insert(project);
}
}
public void update(DbSession session, ProjectDto project) {
- auditPersister.updateComponent(session, new ComponentNewValue(project));
+ auditPersister.updateComponent(session, new ProjectNewValue(project));
mapper(session).update(project);
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.audit.model;
+
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.junit.jupiter.api.Test;
+import org.sonar.db.project.ProjectDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class ProjectNewValueTest {
+
+ @Test
+ void toString_generatesValidJson() throws ParseException {
+ var project = new ProjectDto()
+ .setUuid("uuid")
+ .setName("name")
+ .setKey("key")
+ .setPrivate(true)
+ .setDescription("description")
+ .setQualifier("TRK")
+ .setAiCodeFixEnabled(true);
+ ProjectNewValue newValue = new ProjectNewValue(project);
+
+ JSONObject jsonObject = (JSONObject) new JSONParser().parse(newValue.toString());
+
+ assertThat(jsonObject).hasSize(7);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.config;
+
+public final class AiCodeFixEnablementConstants {
+ public static final String SUGGESTION_FEATURE_ENABLED_PROPERTY = "sonar.ai.suggestions.enabled";
+
+ private AiCodeFixEnablementConstants() {
+ }
+
+}