diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-03-29 14:23:52 +0200 |
---|---|---|
committer | Eric Hartmann <hartmann.eric@gmail.Com> | 2017-04-27 09:23:18 +0200 |
commit | 5c659e207f045706c4408cc9ae72c56a71e545d9 (patch) | |
tree | 01a4092727b6e58c1f66fa6c20a09360028b7482 /server/sonar-ce | |
parent | e62b51e3812f640230c0d0dc191a54e8db76b949 (diff) | |
download | sonarqube-5c659e207f045706c4408cc9ae72c56a71e545d9.tar.gz sonarqube-5c659e207f045706c4408cc9ae72c56a71e545d9.zip |
SONAR-8987 remove use of Guava Optional in CE tables related classes
Diffstat (limited to 'server/sonar-ce')
9 files changed, 20 insertions, 23 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueue.java b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueue.java index 01f5341f764..42447633920 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueue.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueue.java @@ -19,7 +19,7 @@ */ package org.sonar.ce.queue; -import com.google.common.base.Optional; +import java.util.Optional; import javax.annotation.Nullable; import org.sonar.ce.queue.CeQueue; import org.sonar.ce.queue.CeTask; diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java index bcd6f0abccf..8f899d4b2e6 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java @@ -19,12 +19,12 @@ */ package org.sonar.ce.queue; -import com.google.common.base.Optional; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.List; +import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -68,7 +68,7 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue requireNonNull(workerUuid, "workerUuid can't be null"); if (peekPaused.get()) { - return Optional.absent(); + return Optional.empty(); } try (DbSession dbSession = dbClient.openSession(false)) { Optional<CeQueueDto> dto = dbClient.ceQueueDao().peek(dbSession, workerUuid, MAX_EXECUTION_COUNT); @@ -77,7 +77,7 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue task = loadTask(dbSession, dto.get()); queueStatus.addInProgress(); } - return Optional.fromNullable(task); + return Optional.ofNullable(task); } } diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepository.java b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepository.java index 7fbbfa3f3f7..83fb0d01f01 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepository.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepository.java @@ -19,7 +19,7 @@ */ package org.sonar.ce.taskprocessor; -import com.google.common.base.Optional; +import java.util.Optional; import org.sonar.ce.queue.CeTask; import org.sonar.ce.taskprocessor.CeTaskProcessor; diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImpl.java index 24a2bf07530..b96a8e1783f 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImpl.java @@ -21,13 +21,13 @@ package org.sonar.ce.taskprocessor; import com.google.common.base.Function; import com.google.common.base.Joiner; -import com.google.common.base.Optional; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import java.util.Collection; import java.util.Map; +import java.util.Optional; import javax.annotation.Nonnull; import org.sonar.ce.queue.CeTask; import org.sonar.ce.taskprocessor.CeTaskProcessor; @@ -52,7 +52,7 @@ public class CeTaskProcessorRepositoryImpl implements CeTaskProcessorRepository @Override public Optional<CeTaskProcessor> getForCeTask(CeTask ceTask) { - return Optional.fromNullable(taskProcessorByCeTaskType.get(ceTask.getType())); + return Optional.ofNullable(taskProcessorByCeTaskType.get(ceTask.getType())); } private static Map<String, CeTaskProcessor> indexTaskProcessors(CeTaskProcessor[] taskProcessors) { diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerCallableImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerCallableImpl.java index 5bb5a047068..517a0a7651d 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerCallableImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerCallableImpl.java @@ -19,7 +19,7 @@ */ package org.sonar.ce.taskprocessor; -import com.google.common.base.Optional; +import java.util.Optional; import javax.annotation.Nullable; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -67,7 +67,7 @@ public class CeWorkerCallableImpl implements CeWorkerCallable { } catch (Exception e) { LOG.error("Failed to pop the queue of analysis reports", e); } - return Optional.absent(); + return Optional.empty(); } private void executeTask(CeTask task) { diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java index 2bf444730cb..071bd177845 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java @@ -19,13 +19,13 @@ */ package org.sonar.ce.queue; -import com.google.common.base.Optional; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.List; +import java.util.Optional; import java.util.Random; import javax.annotation.Nullable; -import org.assertj.guava.api.Assertions; +import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -49,7 +49,6 @@ import org.sonar.server.organization.DefaultOrganizationProvider; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.startsWith; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -226,7 +225,7 @@ public class InternalCeQueueImplTest { underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error); Optional<CeActivityDto> activityDto = dbTester.getDbClient().ceActivityDao().selectByUuid(session, task.getUuid()); - Assertions.assertThat(activityDto).isPresent(); + assertThat(activityDto).isPresent(); assertThat(activityDto.get().getErrorMessage()).isEqualTo(error.getMessage()); assertThat(activityDto.get().getErrorStacktrace()).isEqualToIgnoringWhitespace(stacktraceToString(error)); @@ -387,7 +386,7 @@ public class InternalCeQueueImplTest { @Test public void fail_to_cancel_if_in_progress() throws Exception { expectedException.expect(IllegalStateException.class); - expectedException.expectMessage(startsWith("Task is in progress and can't be canceled")); + expectedException.expectMessage(Matchers.startsWith("Task is in progress and can't be canceled")); CeTask task = submit(CeTaskTypes.REPORT, "PROJECT_1"); underTest.peek(WORKER_UUID_2); @@ -445,7 +444,7 @@ public class InternalCeQueueImplTest { } private void verifyCanceled(CeQueueDto original) { - Assertions.assertThat(dbTester.getDbClient().ceQueueDao().selectByUuid(dbTester.getSession(), original.getUuid())).isAbsent(); + assertThat(dbTester.getDbClient().ceQueueDao().selectByUuid(dbTester.getSession(), original.getUuid())).isEmpty(); CeActivityDto dto = dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), original.getUuid()).get(); assertThat(dto.getStatus()).isEqualTo(CeActivityDto.Status.CANCELED); assertThat(dto.getExecutionCount()).isEqualTo(original.getExecutionCount()); diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java index 743f51e169d..0e038487294 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java @@ -21,7 +21,6 @@ package org.sonar.ce.taskprocessor; import com.google.common.collect.ImmutableSet; import java.util.Set; -import org.assertj.guava.api.Assertions; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -30,7 +29,6 @@ import org.sonar.ce.queue.CeTaskResult; import static org.assertj.core.api.Assertions.assertThat; - public class CeTaskProcessorRepositoryImplTest { private static final String SOME_CE_TASK_TYPE = "some type"; private static final String SOME_COMPONENT_KEY = "key"; @@ -73,7 +71,7 @@ public class CeTaskProcessorRepositoryImplTest { public void getForTask_returns_absent_if_repository_is_empty() { CeTaskProcessorRepositoryImpl underTest = new CeTaskProcessorRepositoryImpl(new CeTaskProcessor[] {}); - Assertions.assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).isAbsent(); + assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).isEmpty(); } @Test @@ -83,7 +81,7 @@ public class CeTaskProcessorRepositoryImplTest { createCeTaskProcessor(SOME_CE_TASK_TYPE + "_2", SOME_CE_TASK_TYPE + "_3"), }); - Assertions.assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).isAbsent(); + assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).isEmpty(); } @Test diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryRule.java b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryRule.java index 7a07b5e8b8e..c8bebfd5f52 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryRule.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryRule.java @@ -19,9 +19,9 @@ */ package org.sonar.ce.taskprocessor; -import com.google.common.base.Optional; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.junit.rules.ExternalResource; import org.sonar.ce.queue.CeTask; @@ -57,7 +57,7 @@ public class CeTaskProcessorRepositoryRule extends ExternalResource implements C public Optional<CeTaskProcessor> getForCeTask(CeTask ceTask) { CeTaskProcessor taskProcessor = index.get(ceTask.getType()); checkState(taskProcessor != null, "CeTaskProcessor was not set in rule for task %s", ceTask); - return taskProcessor instanceof NoCeTaskProcessor ? Optional.<CeTaskProcessor>absent() : Optional.of(taskProcessor); + return taskProcessor instanceof NoCeTaskProcessor ? Optional.empty() : Optional.of(taskProcessor); } private enum NoCeTaskProcessor implements CeTaskProcessor { diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerCallableImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerCallableImplTest.java index b63a9e0dacc..05c6112ff57 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerCallableImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerCallableImplTest.java @@ -19,8 +19,8 @@ */ package org.sonar.ce.taskprocessor; -import com.google.common.base.Optional; import java.util.List; +import java.util.Optional; import javax.annotation.Nullable; import org.junit.Rule; import org.junit.Test; @@ -59,7 +59,7 @@ public class CeWorkerCallableImplTest { @Test public void no_pending_tasks_in_queue() throws Exception { - when(queue.peek(UNKNOWN_WORKER_UUID)).thenReturn(Optional.<CeTask>absent()); + when(queue.peek(UNKNOWN_WORKER_UUID)).thenReturn(Optional.empty()); assertThat(underTest.call()).isFalse(); |