From 8ae5701135e437ab2747d895144d8a82563051ed Mon Sep 17 00:00:00 2001 From: Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> Date: Fri, 8 Dec 2023 12:51:20 +0100 Subject: [PATCH] SONAR-21121 Add POST /dop-translation/gitlab-configurations/ --- .../org/sonar/auth/gitlab/GitLabSettings.java | 3 ++- .../sonar/auth/gitlab/GitLabSettingsTest.java | 10 +++++----- .../main/java/org/sonar/ce/queue/CeQueue.java | 16 +++++++++++++--- .../java/org/sonar/ce/queue/CeQueueImpl.java | 5 +++++ .../org/sonar/server/common/UpdatedValue.java | 10 +++++++++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java index d81e75e3f82..ff9ea68ee67 100644 --- a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java +++ b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java @@ -19,6 +19,7 @@ */ package org.sonar.auth.gitlab; +import com.google.common.base.Strings; import java.util.Arrays; import java.util.List; import java.util.Set; @@ -88,7 +89,7 @@ public class GitLabSettings implements DevOpsPlatformSettings { } public String provisioningToken() { - return configuration.get(GITLAB_AUTH_PROVISIONING_TOKEN).orElse(null); + return configuration.get(GITLAB_AUTH_PROVISIONING_TOKEN).map(Strings::emptyToNull).orElse(null); } public Set provisioningGroups() { diff --git a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java index ca98c7e8072..85548241db2 100644 --- a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java +++ b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java @@ -41,6 +41,7 @@ public class GitLabSettingsTest { private MapSettings settings; private GitLabSettings config; + @Before public void prepare() { settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, GitLabSettings.definitions())); @@ -92,13 +93,13 @@ public class GitLabSettingsTest { @Test public void isProvisioningEnabled_whenNotSet_returnsFalse() { - enableGithubAuthentication(); + enableGitlabAuthentication(); assertThat(config.isProvisioningEnabled()).isFalse(); } @Test public void isProvisioningEnabled_ifProvisioningDisabled_returnsFalse() { - enableGithubAuthentication(); + enableGitlabAuthentication(); settings.setProperty(GITLAB_AUTH_PROVISIONING_ENABLED, false); assertThat(config.isProvisioningEnabled()).isFalse(); } @@ -111,16 +112,15 @@ public class GitLabSettingsTest { @Test public void isProvisioningEnabled_ifProvisioningEnabledAndGithubAuthEnabled_returnsTrue() { - enableGithubAuthentication(); + enableGitlabAuthentication(); settings.setProperty(GITLAB_AUTH_PROVISIONING_ENABLED, true); assertThat(config.isProvisioningEnabled()).isTrue(); } - private void enableGithubAuthentication() { + private void enableGitlabAuthentication() { settings.setProperty(GITLAB_AUTH_ENABLED, true); settings.setProperty(GITLAB_AUTH_APPLICATION_ID, "on"); settings.setProperty(GITLAB_AUTH_SECRET, "on"); } } - diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java index f0333f07bea..9c7a3f7cc84 100644 --- a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java +++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java @@ -32,7 +32,7 @@ import org.sonar.db.ce.CeQueueDto; * Queue of pending Compute Engine tasks. Both producer and consumer actions * are implemented. *

- * This class is decoupled from the regular task type {@link org.sonar.db.ce.CeTaskTypes#REPORT}. + * This class is decoupled from the regular task type {@link org.sonar.db.ce.CeTaskTypes#REPORT}. *

*/ public interface CeQueue { @@ -60,10 +60,20 @@ public interface CeQueue { * This method is equivalent to calling {@code massSubmit(Collections.singletonList(submission))}. * * @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_ENTITY UNIQUE_QUEUE_PER_MAIN_COMPONENT} - * and there's already a queued task, otherwise the created task. + * and there's already a queued task, otherwise the created task. */ Optional submit(CeTaskSubmit submission, SubmitOption... options); + /** + * Submits a task to the queue. The task is processed asynchronously. + *

+ * This method is equivalent to calling {@code massSubmit(Collections.singletonList(submission))}. + * + * @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_ENTITY UNIQUE_QUEUE_PER_MAIN_COMPONENT} + * and there's already a queued task, otherwise the created task. + */ + Optional submit(DbSession dbSession, CeTaskSubmit submission, SubmitOption... options); + /** * Submits multiple tasks to the queue at once. All tasks are processed asynchronously. *

@@ -93,7 +103,7 @@ public interface CeQueue { * exception is thrown if the status is not {@link org.sonar.db.ce.CeQueueDto.Status#IN_PROGRESS}. * * The {@code dbSession} is committed. - + * @throws RuntimeException if the task is concurrently removed from the queue */ void fail(DbSession dbSession, CeQueueDto ceQueueDto, @Nullable String errorType, @Nullable String errorMessage); diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java index 99c7cfdbd0a..7b043ffdf13 100644 --- a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java +++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java @@ -91,6 +91,11 @@ public class CeQueueImpl implements CeQueue { return submit(submission, toSet(options)); } + @Override + public Optional submit(DbSession dbSession, CeTaskSubmit submission, SubmitOption... options) { + return submit(dbSession, submission, toSet(options)); + } + private Optional submit(CeTaskSubmit submission, Set submitOptions) { try (DbSession dbSession = dbClient.openSession(false)) { Optional ceTask = submit(dbSession, submission, submitOptions); diff --git a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/UpdatedValue.java b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/UpdatedValue.java index 7941773c378..10f3d8783c5 100644 --- a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/UpdatedValue.java +++ b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/UpdatedValue.java @@ -19,10 +19,10 @@ */ package org.sonar.server.common; +import javax.annotation.Nullable; import java.util.Objects; import java.util.function.Consumer; import java.util.function.Function; -import javax.annotation.Nullable; public class UpdatedValue { final T value; @@ -77,4 +77,12 @@ public class UpdatedValue { public int hashCode() { return Objects.hash(value, isDefined); } + + public T orElse(@Nullable T defaultValue) { + if (isDefined) { + return value; + } else { + return defaultValue; + } + } } -- 2.39.5