*/
package org.sonar.auth.gitlab;
+import com.google.common.base.Strings;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
}
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<String> provisioningGroups() {
private MapSettings settings;
private GitLabSettings config;
+
@Before
public void prepare() {
settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, GitLabSettings.definitions()));
@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();
}
@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");
}
}
-
* Queue of pending Compute Engine tasks. Both producer and consumer actions
* are implemented.
* <p>
- * 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}.
* </p>
*/
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<CeTask> submit(CeTaskSubmit submission, SubmitOption... options);
+ /**
+ * Submits a task to the queue. The task is processed asynchronously.
+ * <p>
+ * 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<CeTask> submit(DbSession dbSession, CeTaskSubmit submission, SubmitOption... options);
+
/**
* Submits multiple tasks to the queue at once. All tasks are processed asynchronously.
* <p>
* 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);
return submit(submission, toSet(options));
}
+ @Override
+ public Optional<CeTask> submit(DbSession dbSession, CeTaskSubmit submission, SubmitOption... options) {
+ return submit(dbSession, submission, toSet(options));
+ }
+
private Optional<CeTask> submit(CeTaskSubmit submission, Set<SubmitOption> submitOptions) {
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<CeTask> ceTask = submit(dbSession, submission, submitOptions);
*/
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<T> {
final T value;
public int hashCode() {
return Objects.hash(value, isDefined);
}
+
+ public T orElse(@Nullable T defaultValue) {
+ if (isDefined) {
+ return value;
+ } else {
+ return defaultValue;
+ }
+ }
}