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.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<GoogleComputeEngineApi> {
@Override
@ -85,7 +82,7 @@ public class GoogleComputeEngineApiMetadata extends BaseHttpApiMetadata<GoogleCo
.add(GoogleComputeEngineHttpApiModule.class)
.add(GoogleComputeEngineParserModule.class)
.add(OAuthAuthenticationModule.class)
.add(OAuthModuleWithoutTypeAdapters.class)
.add(OAuthModule.class)
.add(GoogleComputeEngineServiceContextModule.class)
.build());
}

View File

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