From 22a301b6405da9127f4f3a7e89ca1cfc958c208a Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 19 Jan 2013 12:11:12 -0800 Subject: [PATCH] centralize TypeToken creation --- .../src/main/java/org/jclouds/chef/ChefApiMetadata.java | 4 ++-- .../src/main/java/org/jclouds/chef/ChefContextFactory.java | 5 +++-- .../java/org/jclouds/chef/config/ChefRestClientModule.java | 5 +++-- .../src/test/java/org/jclouds/chef/ChefApiLiveTest.java | 3 ++- .../org/jclouds/chef/internal/BaseStubbedOhaiLiveTest.java | 6 ++++-- .../internal/CleanupStaleNodesAndClientsImplLiveTest.java | 4 +++- ...reateNodeAndPopulateAutomaticAttributesImplLiveTest.java | 3 ++- .../internal/DeleteAllApisAndNodesInListImplLiveTest.java | 4 +++- .../chef/strategy/internal/GetNodesImplLiveTest.java | 3 ++- .../UpdateAutomaticAttributesOnNodeImplLiveTest.java | 3 ++- .../jclouds/chef/test/TransientChefApiIntegrationTest.java | 3 ++- 11 files changed, 28 insertions(+), 15 deletions(-) diff --git a/apis/chef/src/main/java/org/jclouds/chef/ChefApiMetadata.java b/apis/chef/src/main/java/org/jclouds/chef/ChefApiMetadata.java index bfac15c04d..bd5ad55560 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/ChefApiMetadata.java +++ b/apis/chef/src/main/java/org/jclouds/chef/ChefApiMetadata.java @@ -23,6 +23,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_TIMEOUTS_PREFIX; import static org.jclouds.chef.config.ChefProperties.CHEF_BOOTSTRAP_DATABAG; +import static org.jclouds.reflect.Reflection2.typeTokenOf; import java.net.URI; import java.util.Properties; @@ -34,7 +35,6 @@ import org.jclouds.ohai.config.JMXOhaiModule; import org.jclouds.rest.internal.BaseRestApiMetadata; import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; import com.google.inject.Module; /** @@ -87,7 +87,7 @@ public class ChefApiMetadata extends BaseRestApiMetadata { .documentation(URI.create("http://wiki.opscode.com/display/chef/Server+API")) .defaultEndpoint("http://localhost:4000") .defaultProperties(ChefApiMetadata.defaultProperties()) - .context(TypeToken.of(ChefContext.class)) + .context(typeTokenOf(ChefContext.class)) .defaultModules(ImmutableSet.>of(ChefRestClientModule.class, ChefParserModule.class, JMXOhaiModule.class)); } diff --git a/apis/chef/src/main/java/org/jclouds/chef/ChefContextFactory.java b/apis/chef/src/main/java/org/jclouds/chef/ChefContextFactory.java index b8358c7244..3df8959b27 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/ChefContextFactory.java +++ b/apis/chef/src/main/java/org/jclouds/chef/ChefContextFactory.java @@ -18,6 +18,8 @@ */ package org.jclouds.chef; +import static org.jclouds.reflect.Reflection2.typeTokenOf; + import java.util.NoSuchElementException; import java.util.Properties; @@ -29,7 +31,6 @@ import org.jclouds.providers.ProviderMetadata; import org.jclouds.providers.Providers; import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; import com.google.inject.Module; /** @@ -124,7 +125,7 @@ public class ChefContextFactory { return ChefContext.class.cast(context); } else if (context instanceof View) { View tctx = View.class.cast(context); - return tctx.unwrap(TypeToken.of(ChefContext.class)); + return tctx.unwrap(typeTokenOf(ChefContext.class)); } else { throw new IllegalArgumentException("provider " + providerOrApi + " contains an unknown context type: " + context.getClass().getSimpleName()); diff --git a/apis/chef/src/main/java/org/jclouds/chef/config/ChefRestClientModule.java b/apis/chef/src/main/java/org/jclouds/chef/config/ChefRestClientModule.java index 76d6f34b4b..d6fa004bd8 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/config/ChefRestClientModule.java +++ b/apis/chef/src/main/java/org/jclouds/chef/config/ChefRestClientModule.java @@ -18,6 +18,8 @@ */ package org.jclouds.chef.config; +import static org.jclouds.reflect.Reflection2.typeTokenOf; + import java.util.List; import javax.inject.Singleton; @@ -32,7 +34,6 @@ import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.scriptbuilder.statements.chef.InstallChefGems; import com.google.common.cache.CacheLoader; -import com.google.common.reflect.TypeToken; import com.google.inject.Provides; import com.google.inject.name.Names; @@ -45,7 +46,7 @@ import com.google.inject.name.Names; public class ChefRestClientModule extends BaseChefRestClientModule { public ChefRestClientModule() { - super(TypeToken.of(ChefApi.class), TypeToken.of(ChefAsyncApi.class)); + super(typeTokenOf(ChefApi.class), typeTokenOf(ChefAsyncApi.class)); } @Provides diff --git a/apis/chef/src/test/java/org/jclouds/chef/ChefApiLiveTest.java b/apis/chef/src/test/java/org/jclouds/chef/ChefApiLiveTest.java index 781a6da827..6ae65fd86e 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/ChefApiLiveTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/ChefApiLiveTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.chef; +import static org.jclouds.reflect.Reflection2.typeTokenOf; import static org.testng.Assert.assertNotNull; import org.jclouds.chef.domain.CookbookVersion; @@ -49,7 +50,7 @@ public class ChefApiLiveTest extends BaseChefApiLiveTest { @Override protected TypeToken contextType() { - return TypeToken.of(ChefContext.class); + return typeTokenOf(ChefContext.class); } } diff --git a/apis/chef/src/test/java/org/jclouds/chef/internal/BaseStubbedOhaiLiveTest.java b/apis/chef/src/test/java/org/jclouds/chef/internal/BaseStubbedOhaiLiveTest.java index 0f3e0698d1..1031a23df2 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/internal/BaseStubbedOhaiLiveTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/internal/BaseStubbedOhaiLiveTest.java @@ -18,11 +18,13 @@ */ package org.jclouds.chef.internal; +import static org.jclouds.reflect.Reflection2.typeTokenOf; + import java.util.Map; import org.jclouds.apis.ApiMetadata; -import org.jclouds.chef.ChefApiMetadata; import org.jclouds.chef.ChefApi; +import org.jclouds.chef.ChefApiMetadata; import org.jclouds.chef.ChefContext; import org.jclouds.chef.config.ChefParserModule; import org.jclouds.chef.config.ChefRestClientModule; @@ -71,6 +73,6 @@ public class BaseStubbedOhaiLiveTest extends BaseChefContextLiveTest contextType() { - return TypeToken.of(ChefContext.class); + return typeTokenOf(ChefContext.class); } } diff --git a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/CleanupStaleNodesAndClientsImplLiveTest.java b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/CleanupStaleNodesAndClientsImplLiveTest.java index c5806ffb2a..15bce92378 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/CleanupStaleNodesAndClientsImplLiveTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/CleanupStaleNodesAndClientsImplLiveTest.java @@ -18,6 +18,8 @@ */ package org.jclouds.chef.strategy.internal; +import static org.jclouds.reflect.Reflection2.typeTokenOf; + import org.jclouds.chef.ChefApi; import org.jclouds.chef.ChefContext; import org.jclouds.chef.internal.BaseChefContextLiveTest; @@ -72,7 +74,7 @@ public class CleanupStaleNodesAndClientsImplLiveTest extends BaseChefContextLive @Override protected TypeToken contextType() { - return TypeToken.of(ChefContext.class); + return typeTokenOf(ChefContext.class); } } diff --git a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/CreateNodeAndPopulateAutomaticAttributesImplLiveTest.java b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/CreateNodeAndPopulateAutomaticAttributesImplLiveTest.java index 04e0c10ee8..fc0f3bed34 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/CreateNodeAndPopulateAutomaticAttributesImplLiveTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/CreateNodeAndPopulateAutomaticAttributesImplLiveTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.chef.strategy.internal; +import static org.jclouds.reflect.Reflection2.typeTokenOf; import static org.testng.Assert.assertEquals; import java.util.Set; @@ -74,7 +75,7 @@ public class CreateNodeAndPopulateAutomaticAttributesImplLiveTest extends BaseCh @Override protected TypeToken contextType() { - return TypeToken.of(ChefContext.class); + return typeTokenOf(ChefContext.class); } } diff --git a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/DeleteAllApisAndNodesInListImplLiveTest.java b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/DeleteAllApisAndNodesInListImplLiveTest.java index f3d399a19c..e66fb70976 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/DeleteAllApisAndNodesInListImplLiveTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/DeleteAllApisAndNodesInListImplLiveTest.java @@ -18,6 +18,8 @@ */ package org.jclouds.chef.strategy.internal; +import static org.jclouds.reflect.Reflection2.typeTokenOf; + import org.jclouds.chef.ChefApi; import org.jclouds.chef.ChefContext; import org.jclouds.chef.internal.BaseChefContextLiveTest; @@ -77,6 +79,6 @@ public class DeleteAllApisAndNodesInListImplLiveTest extends BaseChefContextLive @Override protected TypeToken contextType() { - return TypeToken.of(ChefContext.class); + return typeTokenOf(ChefContext.class); } } diff --git a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/GetNodesImplLiveTest.java b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/GetNodesImplLiveTest.java index 7fab956911..2a2c5c5268 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/GetNodesImplLiveTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/GetNodesImplLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.chef.strategy.internal; import static com.google.common.collect.Iterables.size; +import static org.jclouds.reflect.Reflection2.typeTokenOf; import static org.testng.Assert.assertEquals; import org.jclouds.chef.ChefApi; @@ -94,7 +95,7 @@ public class GetNodesImplLiveTest extends BaseChefContextLiveTest { @Override protected TypeToken contextType() { - return TypeToken.of(ChefContext.class); + return typeTokenOf(ChefContext.class); } } diff --git a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/UpdateAutomaticAttributesOnNodeImplLiveTest.java b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/UpdateAutomaticAttributesOnNodeImplLiveTest.java index bfc1869587..095d7073a8 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/UpdateAutomaticAttributesOnNodeImplLiveTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/strategy/internal/UpdateAutomaticAttributesOnNodeImplLiveTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.chef.strategy.internal; +import static org.jclouds.reflect.Reflection2.typeTokenOf; import static org.testng.Assert.assertEquals; import java.util.Set; @@ -73,6 +74,6 @@ public class UpdateAutomaticAttributesOnNodeImplLiveTest extends BaseChefContext @Override protected TypeToken contextType() { - return TypeToken.of(ChefContext.class); + return typeTokenOf(ChefContext.class); } } diff --git a/apis/chef/src/test/java/org/jclouds/chef/test/TransientChefApiIntegrationTest.java b/apis/chef/src/test/java/org/jclouds/chef/test/TransientChefApiIntegrationTest.java index ccdca2f0c7..c6eaf07437 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/test/TransientChefApiIntegrationTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/test/TransientChefApiIntegrationTest.java @@ -19,6 +19,7 @@ package org.jclouds.chef.test; import static com.google.common.base.Throwables.propagate; +import static org.jclouds.reflect.Reflection2.typeTokenOf; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -105,6 +106,6 @@ public class TransientChefApiIntegrationTest extends BaseChefContextLiveTest contextType() { - return TypeToken.of(ChefContext.class); + return typeTokenOf(ChefContext.class); } }