JCLOUDS-750 At the cost of fiddling with type hierarchy adapters, remove lots of junk with google auto.

This commit is contained in:
Adrian Cole 2014-10-25 15:23:30 -07:00 committed by Adrian Cole
parent 143b5e7e1d
commit d9649c7e1e
3 changed files with 10 additions and 82 deletions

View File

@ -32,16 +32,13 @@ import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.googlecomputeengine.compute.config.GoogleComputeEngineServiceContextModule; import org.jclouds.googlecomputeengine.compute.config.GoogleComputeEngineServiceContextModule;
import org.jclouds.googlecomputeengine.config.GoogleComputeEngineHttpApiModule; import org.jclouds.googlecomputeengine.config.GoogleComputeEngineHttpApiModule;
import org.jclouds.googlecomputeengine.config.GoogleComputeEngineParserModule; 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.OAuthAuthenticationModule;
import org.jclouds.oauth.v2.config.OAuthModule;
import org.jclouds.rest.internal.BaseHttpApiMetadata; import org.jclouds.rest.internal.BaseHttpApiMetadata;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Module; import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for GoogleCompute v1 API
*/
public class GoogleComputeEngineApiMetadata extends BaseHttpApiMetadata<GoogleComputeEngineApi> { public class GoogleComputeEngineApiMetadata extends BaseHttpApiMetadata<GoogleComputeEngineApi> {
@Override @Override
@ -85,7 +82,7 @@ public class GoogleComputeEngineApiMetadata extends BaseHttpApiMetadata<GoogleCo
.add(GoogleComputeEngineHttpApiModule.class) .add(GoogleComputeEngineHttpApiModule.class)
.add(GoogleComputeEngineParserModule.class) .add(GoogleComputeEngineParserModule.class)
.add(OAuthAuthenticationModule.class) .add(OAuthAuthenticationModule.class)
.add(OAuthModuleWithoutTypeAdapters.class) .add(OAuthModule.class)
.add(GoogleComputeEngineServiceContextModule.class) .add(GoogleComputeEngineServiceContextModule.class)
.build()); .build());
} }

View File

@ -38,10 +38,7 @@ import org.jclouds.googlecomputeengine.options.FirewallOptions;
import org.jclouds.googlecomputeengine.options.RouteOptions; import org.jclouds.googlecomputeengine.options.RouteOptions;
import org.jclouds.json.config.GsonModule; import org.jclouds.json.config.GsonModule;
import org.jclouds.net.domain.IpProtocol; import org.jclouds.net.domain.IpProtocol;
import org.jclouds.oauth.v2.domain.ClaimSet; import org.jclouds.oauth.v2.config.OAuthParserModule;
import org.jclouds.oauth.v2.domain.Header;
import org.jclouds.oauth.v2.json.ClaimSetTypeAdapter;
import org.jclouds.oauth.v2.json.HeaderTypeAdapter;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Range; import com.google.common.collect.Range;
@ -54,24 +51,24 @@ import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapterFactory;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
public class GoogleComputeEngineParserModule extends AbstractModule { public class GoogleComputeEngineParserModule extends AbstractModule {
@Override @Override protected void configure() {
protected void configure() {
bind(GsonModule.DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class); bind(GsonModule.DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class);
} }
@Provides @Provides @Singleton public Set<TypeAdapterFactory> typeAdapterFactories() {
@Singleton return new OAuthParserModule().typeAdapterFactories();
public Map<Type, Object> provideCustomAdapterBindings() { }
@Provides @Singleton public Map<Type, Object> typeAdapters() {
return new ImmutableMap.Builder<Type, Object>() return new ImmutableMap.Builder<Type, Object>()
.put(Metadata.class, new MetadataTypeAdapter()) .put(Metadata.class, new MetadataTypeAdapter())
.put(Operation.class, new OperationTypeAdapter()) .put(Operation.class, new OperationTypeAdapter())
.put(Header.class, new HeaderTypeAdapter())
.put(ClaimSet.class, new ClaimSetTypeAdapter())
.put(Project.class, new ProjectTypeAdapter()) .put(Project.class, new ProjectTypeAdapter())
.put(Instance.class, new InstanceTypeAdapter()) .put(Instance.class, new InstanceTypeAdapter())
.put(InstanceTemplate.class, new InstanceTemplateTypeAdapter()) .put(InstanceTemplate.class, new InstanceTemplateTypeAdapter())
@ -86,7 +83,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
* *
* @see <a href="https://developers.google.com/compute/docs/reference/v1/operations"/> * @see <a href="https://developers.google.com/compute/docs/reference/v1/operations"/>
*/ */
@Singleton
private static class OperationTypeAdapter implements JsonDeserializer<Operation> { private static class OperationTypeAdapter implements JsonDeserializer<Operation> {
@Override @Override
@ -124,7 +120,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
} }
} }
@Singleton
private static class InstanceTemplateTypeAdapter implements JsonSerializer<InstanceTemplate> { private static class InstanceTemplateTypeAdapter implements JsonSerializer<InstanceTemplate> {
@Override @Override
@ -175,7 +170,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
} }
} }
@Singleton
private static class InstanceTypeAdapter implements JsonDeserializer<Instance> { private static class InstanceTypeAdapter implements JsonDeserializer<Instance> {
@Override @Override
@ -218,13 +212,8 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
} }
} }
/**
* Parser for Metadata.
*/
@Singleton
private static class MetadataTypeAdapter implements JsonDeserializer<Metadata>, JsonSerializer<Metadata> { private static class MetadataTypeAdapter implements JsonDeserializer<Metadata>, JsonSerializer<Metadata> {
@Override @Override
public Metadata deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws public Metadata deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
JsonParseException { JsonParseException {
@ -265,9 +254,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
} }
} }
@Singleton
private static class ProjectTypeAdapter implements JsonDeserializer<Project> { private static class ProjectTypeAdapter implements JsonDeserializer<Project> {
@Override @Override
@ -291,7 +277,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
} }
} }
@Singleton
private static class FirewallOptionsTypeAdapter implements JsonSerializer<FirewallOptions> { private static class FirewallOptionsTypeAdapter implements JsonSerializer<FirewallOptions> {
@Override @Override
@ -323,7 +308,6 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
} }
} }
@Singleton
private static class RouteOptionsTypeAdapter implements JsonSerializer<RouteOptions> { private static class RouteOptionsTypeAdapter implements JsonSerializer<RouteOptions> {
@Override @Override

View File

@ -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.
* <p/>
* TODO overcome this by using multibindings on GSonModule?
*/
public class OAuthModuleWithoutTypeAdapters extends OAuthModule {
@Override
protected void configure() {
bind(new TypeLiteral<Function<byte[], byte[]>>() {
}).to(SignOrProduceMacForToken.class);
bind(new TypeLiteral<Supplier<OAuthCredentials>>() {
}).to(OAuthCredentialsSupplier.class);
bind(new TypeLiteral<Function<GeneratedHttpRequest, TokenRequest>>() {
}).to(BuildTokenRequest.class);
bind(new TypeLiteral<Function<TokenRequest, Token>>() {
}).to(FetchToken.class);
bind(CredentialType.class).toProvider(OAuthModule.CredentialTypeFromPropertyOrDefault.class);
}
}