Fix dependency graph and replace Guava

This commit is contained in:
Alexander Söderberg 2020-09-28 16:05:14 +02:00 committed by Alexander Söderberg
parent 4ca47777a3
commit e914d04450
35 changed files with 184 additions and 191 deletions

View file

@ -111,7 +111,7 @@ public class DefaultMockService implements MockService {
Example Registration:
```java
servicePipeline.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService());
servicePipeline.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
```
Example Usage:

View file

@ -1,4 +1,3 @@
dependencies {
/* Exposed by Core later on */
implementation 'com.google.guava:guava:29.0-jre'
api 'io.leangen.geantyref:geantyref:1.3.4'
}

View file

@ -23,7 +23,6 @@
//
package cloud.commandframework.services;
import com.google.common.base.Objects;
import cloud.commandframework.services.annotations.Order;
import cloud.commandframework.services.types.Service;
@ -32,6 +31,7 @@ import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.util.Objects;
class AnnotatedMethodService<Context, Result> implements Service<Context, Result> {
@ -87,12 +87,12 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
return false;
}
final AnnotatedMethodService<?, ?> that = (AnnotatedMethodService<?, ?>) o;
return Objects.equal(this.methodHandle, that.methodHandle);
return Objects.equals(this.methodHandle, that.methodHandle);
}
@Override
public int hashCode() {
return Objects.hashCode(this.methodHandle);
return Objects.hash(this.methodHandle);
}
}

View file

@ -23,7 +23,7 @@
//
package cloud.commandframework.services;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.annotations.ServiceImplementation;
import cloud.commandframework.services.types.Service;
@ -53,7 +53,7 @@ enum AnnotatedMethodServiceFactory {
}
map.put(new AnnotatedMethodService<>(instance, method),
TypeToken.of(serviceImplementation.value()));
TypeToken.get(serviceImplementation.value()));
}
return map;
}

View file

@ -23,7 +23,7 @@
//
package cloud.commandframework.services;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.types.Service;
import javax.annotation.Nonnull;
@ -166,7 +166,7 @@ public final class ServicePipeline {
@Nonnull final Class<? extends Service<Context, Result>> type,
@Nonnull final Service<Context, Result> implementation,
@Nonnull final Collection<Predicate<Context>> filters) {
return registerServiceImplementation(TypeToken.of(type), implementation, filters);
return registerServiceImplementation(TypeToken.get(type), implementation, filters);
}
/**
@ -227,7 +227,7 @@ public final class ServicePipeline {
Collections.reverse(queue);
for (ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>> wrapper : queue) {
collection
.add((TypeToken<? extends S>) TypeToken.of(wrapper.getImplementation().getClass()));
.add((TypeToken<? extends S>) TypeToken.get(wrapper.getImplementation().getClass()));
}
return Collections.unmodifiableList(collection);
}

View file

@ -23,9 +23,8 @@
//
package cloud.commandframework.services;
import com.google.common.base.Preconditions;
import javax.annotation.Nonnull;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@ -59,7 +58,7 @@ public final class ServicePipelineBuilder {
*/
@Nonnull
public ServicePipelineBuilder withExecutor(@Nonnull final Executor executor) {
this.executor = Preconditions.checkNotNull(executor, "Executor may not be null");
this.executor = Objects.requireNonNull(executor, "Executor may not be null");
return this;
}

View file

@ -23,8 +23,8 @@
//
package cloud.commandframework.services;
import com.google.common.reflect.TypeToken;
import cloud.commandframework.services.types.Service;
import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull;
@ -66,7 +66,7 @@ public final class ServicePump<Context> {
@Nonnull
public <Result> ServiceSpigot<Context, Result> through(
@Nonnull final Class<? extends Service<Context, Result>> clazz) {
return this.through(TypeToken.of(clazz));
return this.through(TypeToken.get(clazz));
}
}

View file

@ -23,7 +23,7 @@
//
package cloud.commandframework.services;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.annotations.Order;
import cloud.commandframework.services.types.Service;
@ -136,7 +136,7 @@ public final class ServiceRepository<Context, Response> {
public String toString() {
return String
.format("ServiceWrapper{type=%s,implementation=%s}", serviceType.toString(),
TypeToken.of(implementation.getClass()).toString());
TypeToken.get(implementation.getClass()).toString());
}
@Override

View file

@ -23,7 +23,7 @@
//
package cloud.commandframework.services;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.types.ConsumerService;
import cloud.commandframework.services.types.Service;
import cloud.commandframework.services.types.SideEffectService;

View file

@ -23,7 +23,8 @@
//
package cloud.commandframework.services;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.mock.*;
import cloud.commandframework.services.types.Service;
import org.junit.jupiter.api.Assertions;
@ -38,12 +39,12 @@ public class ServicesTest {
final ServicePipeline servicePipeline = ServicePipeline.builder().build();
Assertions.assertNotNull(servicePipeline);
servicePipeline
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService());
.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
Assertions.assertThrows(IllegalArgumentException.class, () -> servicePipeline
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService()));
.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService()));
final SecondaryMockService secondaryMockService = new SecondaryMockService();
servicePipeline
.registerServiceImplementation(TypeToken.of(MockService.class), secondaryMockService,
.registerServiceImplementation(TypeToken.get(MockService.class), secondaryMockService,
Collections.singleton(secondaryMockService));
servicePipeline.registerServiceImplementation(MockService.class,
mockContext -> new MockService.MockResult(-91),
@ -69,7 +70,7 @@ public class ServicesTest {
@Test
public void testSideEffectServices() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build();
servicePipeline.registerServiceType(TypeToken.of(MockSideEffectService.class),
servicePipeline.registerServiceType(TypeToken.get(MockSideEffectService.class),
new DefaultSideEffectService());
final MockSideEffectService.MockPlayer mockPlayer =
new MockSideEffectService.MockPlayer(20);
@ -88,8 +89,8 @@ public class ServicesTest {
@Test
public void testForwarding() throws Exception {
final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService())
.registerServiceType(TypeToken.of(MockResultConsumer.class), new MockResultConsumer());
.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService())
.registerServiceType(TypeToken.get(MockResultConsumer.class), new MockResultConsumer());
Assertions.assertEquals(State.ACCEPTED,
servicePipeline.pump(new MockService.MockContext("huh")).through(MockService.class)
.forward().through(MockResultConsumer.class).getResult());
@ -103,7 +104,7 @@ public class ServicesTest {
@Test
public void testSorting() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService());
.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedFirst(),
Collections.emptyList());
servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedLast(),
@ -117,21 +118,21 @@ public class ServicesTest {
@Test
public void testRecognisedTypes() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService());
.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
Assertions.assertEquals(1, servicePipeline.getRecognizedTypes().size());
}
@Test
public void testImplementationGetters() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService());
.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedFirst(),
Collections.emptyList());
servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedLast(),
Collections.emptyList());
final TypeToken<? extends Service<?, ?>> first = TypeToken.of(MockOrderedFirst.class),
last = TypeToken.of(MockOrderedLast.class);
final TypeToken<MockService> mockServiceType = TypeToken.of(MockService.class);
final TypeToken<? extends Service<?, ?>> first = TypeToken.get(MockOrderedFirst.class),
last = TypeToken.get(MockOrderedLast.class);
final TypeToken<MockService> mockServiceType = TypeToken.get(MockService.class);
for (TypeToken<?> typeToken : servicePipeline.getRecognizedTypes()) {
Assertions.assertEquals(mockServiceType, typeToken);
}
@ -142,13 +143,13 @@ public class ServicesTest {
iterator = impls.iterator();
Assertions.assertEquals(first, iterator.next());
Assertions.assertEquals(last, iterator.next());
Assertions.assertEquals(DefaultMockService.class, iterator.next().getRawType());
Assertions.assertEquals(DefaultMockService.class, GenericTypeReflector.erase(iterator.next().getType()));
}
@Test
public void testAnnotatedMethods() throws Exception {
final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService())
.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService())
.registerMethods(new AnnotatedMethodTest());
final String testString = UUID.randomUUID().toString();
Assertions.assertEquals(testString.length(),
@ -159,7 +160,7 @@ public class ServicesTest {
@Test
public void testConsumerServices() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockConsumerService.class),
.registerServiceType(TypeToken.get(MockConsumerService.class),
new StateSettingConsumerService())
.registerServiceImplementation(MockConsumerService.class,
new InterruptingMockConsumer(), Collections.emptyList());
@ -171,7 +172,7 @@ public class ServicesTest {
@Test
public void testPartialResultServices() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockPartialResultService.class),
.registerServiceType(TypeToken.get(MockPartialResultService.class),
new DefaultPartialRequestService())
.registerServiceImplementation(MockPartialResultService.class,
new CompletingPartialResultService(), Collections.emptyList());
@ -191,7 +192,7 @@ public class ServicesTest {
final ServicePipeline servicePipeline = ServicePipeline.builder().build();
Assertions.assertNotNull(servicePipeline);
servicePipeline
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService());
.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
final PipelineException pipelineException = Assertions.assertThrows(PipelineException.class,
() -> servicePipeline.pump(new MockService.MockContext("pls throw exception"))
.through(MockService.class).getResult());