Merge pull request #37 from iocanel/12

Remove occurrences of guava.

fixes gh-12
This commit is contained in:
Spencer Gibb
2017-01-16 14:56:12 -05:00
committed by GitHub
6 changed files with 68 additions and 11 deletions

View File

@@ -209,7 +209,6 @@
<include>io.reactivex:*</include>
<include>io.zipkin.java:*</include>
<include>io.netty:*</include>
<include>com.google.guava:*</include>
<include>commons-*:*</include>
</includes>
</dependencies>

View File

@@ -17,7 +17,6 @@
package org.springframework.cloud.kubernetes.archaius;
import com.google.common.base.Strings;
import com.netflix.config.WatchedConfigurationSource;
import com.netflix.config.WatchedUpdateListener;
import com.netflix.config.WatchedUpdateResult;
@@ -26,8 +25,10 @@ import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.StringUtils;
import java.io.Closeable;
import java.io.IOException;
@@ -72,14 +73,14 @@ public class ArchaiusConfigMapSourceConfiguration implements InitializingBean, D
public void start() {
ConfigMap map = Strings.isNullOrEmpty(namespace)
ConfigMap map = StringUtils.isEmpty(namespace)
? client.configMaps().withName(name).get()
: client.configMaps().inNamespace(namespace).withName(name).get();
if (map != null) {
currentData.set(asObjectMap(map.getData()));
}
watch = Strings.isNullOrEmpty(namespace)
watch = StringUtils.isEmpty(namespace)
? client.configMaps().withName(name).watch(watcher)
: client.configMaps().inNamespace(namespace).withName(namespace).watch(watcher);
started.set(true);

View File

@@ -98,11 +98,6 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -26,7 +26,6 @@ import java.util.Set;
import org.springframework.util.Assert;
import com.google.common.reflect.TypeToken;
import com.netflix.client.config.IClientConfigKey;
public abstract class KubernetesConfigKey<T> implements IClientConfigKey<T> {
@@ -93,7 +92,7 @@ public abstract class KubernetesConfigKey<T> implements IClientConfigKey<T> {
Assert.isTrue(superclass instanceof ParameterizedType,
superclass + " isn't parameterized");
Type runtimeType = ((ParameterizedType) superclass).getActualTypeArguments()[0];
type = (Class<T>) TypeToken.of(runtimeType).getRawType();
type = (Class<T>) Types.rawType(runtimeType);
}
@Override

View File

@@ -0,0 +1,36 @@
package org.springframework.cloud.kubernetes.ribbon;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.Set;
final class Types {
private Types() {
//Utlity
}
static Class rawType(Type type) {
if (type instanceof Class) {
return (Class) type;
} else if (type instanceof TypeVariable) {
return rawType(firstOrObject(((TypeVariable) type).getBounds()));
} else if (type instanceof WildcardType) {
return rawType(firstOrObject(((WildcardType) type).getUpperBounds()));
} else if (type instanceof GenericArrayType) {
return rawType(((GenericArrayType) type).getGenericComponentType());
}
return Object.class;
}
private static Type firstOrObject(Type[] types) {
if (types.length > 0) {
return rawType(types[0]);
} else {
return Void.class;
}
}
}

View File

@@ -0,0 +1,27 @@
package org.springframework.cloud.kubernetes.ribbon;
import org.junit.Assert;
import org.junit.Test;
public class KubernetesConfigKeyTest {
private class TypeOne<T> {}
@Test
public <T extends TypeOne, I> void testTypes() {
//with class
KubernetesConfigKey<String> key1 = new KubernetesConfigKey<String>("key1"){};
//with type variable
KubernetesConfigKey<T> key2 = new KubernetesConfigKey<T>("key2"){};
//with type variable with no bounds
KubernetesConfigKey<I> key3 = new KubernetesConfigKey<I>("key3"){};
Assert.assertEquals(String.class, key1.type());
Assert.assertEquals(TypeOne.class, key2.type());
Assert.assertEquals(Object.class, key3.type());
}
}