From d9649c7e1ef52338d83a1fb271d8b805abb4653f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 25 Oct 2014 15:23:30 -0700 Subject: [PATCH] JCLOUDS-750 At the cost of fiddling with type hierarchy adapters, remove lots of junk with google auto. --- .../GoogleComputeEngineApiMetadata.java | 7 +-- .../GoogleComputeEngineParserModule.java | 32 +++-------- .../OAuthModuleWithoutTypeAdapters.java | 53 ------------------- 3 files changed, 10 insertions(+), 82 deletions(-) delete mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java index 544a8511ce..b63a69fb80 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java @@ -32,16 +32,13 @@ import org.jclouds.compute.ComputeServiceContext; import org.jclouds.googlecomputeengine.compute.config.GoogleComputeEngineServiceContextModule; import org.jclouds.googlecomputeengine.config.GoogleComputeEngineHttpApiModule; import org.jclouds.googlecomputeengine.config.GoogleComputeEngineParserModule; -import org.jclouds.googlecomputeengine.config.OAuthModuleWithoutTypeAdapters; import org.jclouds.oauth.v2.config.OAuthAuthenticationModule; +import org.jclouds.oauth.v2.config.OAuthModule; import org.jclouds.rest.internal.BaseHttpApiMetadata; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; -/** - * Implementation of {@link ApiMetadata} for GoogleCompute v1 API - */ public class GoogleComputeEngineApiMetadata extends BaseHttpApiMetadata { @Override @@ -85,7 +82,7 @@ public class GoogleComputeEngineApiMetadata extends BaseHttpApiMetadata provideCustomAdapterBindings() { + @Provides @Singleton public Set typeAdapterFactories() { + return new OAuthParserModule().typeAdapterFactories(); + } + + @Provides @Singleton public Map typeAdapters() { return new ImmutableMap.Builder() .put(Metadata.class, new MetadataTypeAdapter()) .put(Operation.class, new OperationTypeAdapter()) - .put(Header.class, new HeaderTypeAdapter()) - .put(ClaimSet.class, new ClaimSetTypeAdapter()) .put(Project.class, new ProjectTypeAdapter()) .put(Instance.class, new InstanceTypeAdapter()) .put(InstanceTemplate.class, new InstanceTemplateTypeAdapter()) @@ -86,7 +83,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule { * * @see */ - @Singleton private static class OperationTypeAdapter implements JsonDeserializer { @Override @@ -124,7 +120,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule { } } - @Singleton private static class InstanceTemplateTypeAdapter implements JsonSerializer { @Override @@ -175,7 +170,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule { } } - @Singleton private static class InstanceTypeAdapter implements JsonDeserializer { @Override @@ -218,13 +212,8 @@ public class GoogleComputeEngineParserModule extends AbstractModule { } } - /** - * Parser for Metadata. - */ - @Singleton private static class MetadataTypeAdapter implements JsonDeserializer, JsonSerializer { - @Override public Metadata deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { @@ -265,9 +254,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule { } } - - - @Singleton private static class ProjectTypeAdapter implements JsonDeserializer { @Override @@ -291,7 +277,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule { } } - @Singleton private static class FirewallOptionsTypeAdapter implements JsonSerializer { @Override @@ -323,7 +308,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule { } } - @Singleton private static class RouteOptionsTypeAdapter implements JsonSerializer { @Override diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java deleted file mode 100644 index 03f2f46534..0000000000 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.googlecomputeengine.config; - -import org.jclouds.oauth.v2.config.CredentialType; -import org.jclouds.oauth.v2.config.OAuthModule; -import org.jclouds.oauth.v2.domain.OAuthCredentials; -import org.jclouds.oauth.v2.domain.Token; -import org.jclouds.oauth.v2.domain.TokenRequest; -import org.jclouds.oauth.v2.functions.BuildTokenRequest; -import org.jclouds.oauth.v2.functions.FetchToken; -import org.jclouds.oauth.v2.functions.OAuthCredentialsSupplier; -import org.jclouds.oauth.v2.functions.SignOrProduceMacForToken; -import org.jclouds.rest.internal.GeneratedHttpRequest; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.inject.TypeLiteral; - -/** - * Overrides OAuthModule leaving TypeAdapters bindings out. - *

- * TODO overcome this by using multibindings on GSonModule? - */ -public class OAuthModuleWithoutTypeAdapters extends OAuthModule { - - @Override - protected void configure() { - bind(new TypeLiteral>() { - }).to(SignOrProduceMacForToken.class); - bind(new TypeLiteral>() { - }).to(OAuthCredentialsSupplier.class); - bind(new TypeLiteral>() { - }).to(BuildTokenRequest.class); - bind(new TypeLiteral>() { - }).to(FetchToken.class); - bind(CredentialType.class).toProvider(OAuthModule.CredentialTypeFromPropertyOrDefault.class); - } -}