Repository: jclouds-labs-google
Updated Branches:
  refs/heads/master 627667018 -> f191c8fb0


http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/main/java/org/jclouds/googlecloud/domain/ForwardingListPage.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/main/java/org/jclouds/googlecloud/domain/ForwardingListPage.java
 
b/googlecloud/src/main/java/org/jclouds/googlecloud/domain/ForwardingListPage.java
new file mode 100644
index 0000000..f2aaa10
--- /dev/null
+++ 
b/googlecloud/src/main/java/org/jclouds/googlecloud/domain/ForwardingListPage.java
@@ -0,0 +1,51 @@
+/*
+ * 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.googlecloud.domain;
+
+import java.beans.ConstructorProperties;
+import java.util.List;
+
+import org.jclouds.googlecloud.internal.NullSafeCopies;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.collect.ForwardingList;
+
+/** An immutable list that includes a token, if there is another page 
available. */
+public final class ForwardingListPage<T> extends ForwardingList<T> implements 
ListPage<T> {
+
+   private final List<T> items;
+   private final String nextPageToken;
+
+   @ConstructorProperties({ "items", "nextPageToken" }) 
ForwardingListPage(List<T> items, String nextPageToken) {
+      this.items = NullSafeCopies.copyOf(items);
+      this.nextPageToken = nextPageToken;
+   }
+
+   public static <T> ListPage<T> create(List<T> items, String nextPageToken) {
+      return new ForwardingListPage<T>(items, nextPageToken);
+   }
+
+   @Override @Nullable public String nextPageToken() {
+      return nextPageToken;
+   }
+
+   @Override protected List<T> delegate() {
+      return items;
+   }
+
+}
+

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/main/java/org/jclouds/googlecloud/domain/ListPage.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/main/java/org/jclouds/googlecloud/domain/ListPage.java 
b/googlecloud/src/main/java/org/jclouds/googlecloud/domain/ListPage.java
new file mode 100644
index 0000000..dc6c5aa
--- /dev/null
+++ b/googlecloud/src/main/java/org/jclouds/googlecloud/domain/ListPage.java
@@ -0,0 +1,28 @@
+/*
+ * 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.googlecloud.domain;
+
+import java.util.List;
+
+import org.jclouds.javax.annotation.Nullable;
+
+/** An immutable list that includes a token, if there is another page 
available. */
+public interface ListPage<T> extends List<T> {
+   /** Indicates more data is available. */
+   @Nullable String nextPageToken();
+}
+

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/main/java/org/jclouds/googlecloud/internal/AdvancingIterator.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/main/java/org/jclouds/googlecloud/internal/AdvancingIterator.java
 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/AdvancingIterator.java
new file mode 100644
index 0000000..0010804
--- /dev/null
+++ 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/AdvancingIterator.java
@@ -0,0 +1,48 @@
+/*
+ * 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.googlecloud.internal;
+
+import org.jclouds.googlecloud.domain.ListPage;
+
+import com.google.common.base.Function;
+import com.google.common.collect.AbstractIterator;
+
+final class AdvancingIterator<T> extends AbstractIterator<ListPage<T>> {
+
+   private final Function<String, ListPage<T>> tokenToNext;
+   private ListPage<T> current;
+   private boolean unread = true;
+
+   AdvancingIterator(ListPage<T> initial, Function<String, ListPage<T>> 
tokenToNext) {
+      this.current = initial;
+      this.tokenToNext = tokenToNext;
+   }
+
+   @Override protected ListPage<T> computeNext() {
+      if (unread) {
+         try {
+            return current;
+         } finally {
+            unread = false;
+         }
+      } else if (current.nextPageToken() != null) {
+         return current = tokenToNext.apply(current.nextPageToken());
+      } else {
+         return endOfData();
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseArg0ToIteratorOfListPage.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseArg0ToIteratorOfListPage.java
 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseArg0ToIteratorOfListPage.java
new file mode 100644
index 0000000..3aaa517
--- /dev/null
+++ 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseArg0ToIteratorOfListPage.java
@@ -0,0 +1,58 @@
+/*
+ * 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.googlecloud.internal;
+
+import java.util.Iterator;
+
+import org.jclouds.googlecloud.domain.ListPage;
+import org.jclouds.googlecloud.options.ListOptions;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.InvocationContext;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+
+import com.google.common.base.Function;
+
+public abstract class BaseArg0ToIteratorOfListPage<T, O extends ListOptions, I 
extends BaseArg0ToIteratorOfListPage<T, O, I>>
+      implements Function<ListPage<T>, Iterator<ListPage<T>>>, 
InvocationContext<I> {
+
+   private GeneratedHttpRequest request;
+
+   @Override public Iterator<ListPage<T>> apply(ListPage<T> input) {
+      if (input.nextPageToken() == null) {
+         return ListPages.singletonOrEmptyIterator(input);
+      }
+
+      String arg0 = (String) request.getInvocation().getArgs().get(0);
+      O options = ListPages.listOptions(request.getInvocation().getArgs());
+
+      return new AdvancingIterator<T>(input, fetchNextPage(arg0, options));
+   }
+
+   /**
+    * This is used when you need to close over the first argument of this api.
+    *
+    * <p/> For example, {@code arg0} will become "myzone", which you can use 
to ensure the next page goes to the
+    * same zone: <pre>{@code api.operations().listInZone("myzone")}</pre>
+    */
+   protected abstract Function<String, ListPage<T>> fetchNextPage(String arg0, 
O options);
+
+   @SuppressWarnings("unchecked")
+   @Override public I setContext(HttpRequest request) {
+      this.request = GeneratedHttpRequest.class.cast(request);
+      return (I) this;
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseCallerArg0ToIteratorOfListPage.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseCallerArg0ToIteratorOfListPage.java
 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseCallerArg0ToIteratorOfListPage.java
new file mode 100644
index 0000000..f1fef2d
--- /dev/null
+++ 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseCallerArg0ToIteratorOfListPage.java
@@ -0,0 +1,58 @@
+/*
+ * 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.googlecloud.internal;
+
+import java.util.Iterator;
+
+import org.jclouds.googlecloud.domain.ListPage;
+import org.jclouds.googlecloud.options.ListOptions;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.InvocationContext;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+
+import com.google.common.base.Function;
+
+public abstract class BaseCallerArg0ToIteratorOfListPage<T, O extends 
ListOptions, I extends BaseCallerArg0ToIteratorOfListPage<T, O, I>>
+      implements Function<ListPage<T>, Iterator<ListPage<T>>>, 
InvocationContext<I> {
+
+   private GeneratedHttpRequest request;
+
+   @Override public Iterator<ListPage<T>> apply(ListPage<T> input) {
+      if (input.nextPageToken() == null) {
+         return ListPages.singletonOrEmptyIterator(input);
+      }
+
+      String arg0 = (String) request.getCaller().get().getArgs().get(0);
+      O options = ListPages.listOptions(request.getInvocation().getArgs());
+
+      return new AdvancingIterator<T>(input, fetchNextPage(arg0, options));
+   }
+
+   /**
+    * This is used when you need to close over the argument that created the 
api.
+    *
+    * <p/> For example, {@code callerArg0} will become "myzone", which you can 
use to ensure the next page goes to the
+    * same zone: <pre>{@code api.instancesInZone("myzone").list()}</pre>
+    */
+   protected abstract Function<String, ListPage<T>> fetchNextPage(String 
callerArg0, O options);
+
+   @SuppressWarnings("unchecked")
+   @Override public I setContext(HttpRequest request) {
+      this.request = GeneratedHttpRequest.class.cast(request);
+      return (I) this;
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseToIteratorOfListPage.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseToIteratorOfListPage.java
 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseToIteratorOfListPage.java
new file mode 100644
index 0000000..364a183
--- /dev/null
+++ 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/BaseToIteratorOfListPage.java
@@ -0,0 +1,49 @@
+/*
+ * 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.googlecloud.internal;
+
+import java.util.Iterator;
+
+import org.jclouds.googlecloud.domain.ListPage;
+import org.jclouds.googlecloud.options.ListOptions;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.InvocationContext;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+
+import com.google.common.base.Function;
+
+public abstract class BaseToIteratorOfListPage<T, O extends ListOptions, I 
extends BaseToIteratorOfListPage<T, O, I>>
+      implements Function<ListPage<T>, Iterator<ListPage<T>>>, 
InvocationContext<I> {
+
+   private GeneratedHttpRequest request;
+
+   @Override public Iterator<ListPage<T>> apply(ListPage<T> input) {
+      if (input.nextPageToken() == null) {
+         return ListPages.singletonOrEmptyIterator(input);
+      }
+      return new AdvancingIterator<T>(input,
+            
fetchNextPage(ListPages.<O>listOptions(request.getInvocation().getArgs())));
+   }
+
+   protected abstract Function<String, ListPage<T>> fetchNextPage(O options);
+
+   @SuppressWarnings("unchecked")
+   @Override public I setContext(HttpRequest request) {
+      this.request = GeneratedHttpRequest.class.cast(request);
+      return (I) this;
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/main/java/org/jclouds/googlecloud/internal/ListPages.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/main/java/org/jclouds/googlecloud/internal/ListPages.java 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/ListPages.java
new file mode 100644
index 0000000..b874ca0
--- /dev/null
+++ b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/ListPages.java
@@ -0,0 +1,57 @@
+/*
+ * 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.googlecloud.internal;
+
+import static com.google.common.base.Predicates.instanceOf;
+import static com.google.common.collect.Iterables.tryFind;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.jclouds.googlecloud.domain.ListPage;
+import org.jclouds.googlecloud.options.ListOptions;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.collect.AbstractIterator;
+import com.google.common.collect.Iterators;
+
+public final class ListPages {
+
+   public static <T> Iterable<T> concat(final Iterator<ListPage<T>> input) {
+      return new Iterable<T>() {
+         @Override public Iterator<T> iterator() {
+            return Iterators.concat(new AbstractIterator<Iterator<T>>() {
+               @Override protected Iterator<T> computeNext() {
+                  return input.hasNext() ? input.next().iterator() : 
endOfData();
+               }
+            });
+         }
+      };
+   }
+
+   /** Value of {@code <O>} is a final class in the cloud provider. Rather 
than playing with reflection, we trust it. */
+   @Nullable static <O extends ListOptions> O listOptions(List<Object> args) {
+      return (O) tryFind(args, instanceOf(ListOptions.class)).orNull();
+   }
+
+   static <T> Iterator<ListPage<T>> singletonOrEmptyIterator(ListPage<T> 
input) {
+      return input.isEmpty() ? Iterators.<ListPage<T>>emptyIterator() : 
Iterators.singletonIterator(input);
+   }
+
+   private ListPages() {
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/main/java/org/jclouds/googlecloud/internal/NullSafeCopies.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/main/java/org/jclouds/googlecloud/internal/NullSafeCopies.java
 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/NullSafeCopies.java
new file mode 100644
index 0000000..c1a0692
--- /dev/null
+++ 
b/googlecloud/src/main/java/org/jclouds/googlecloud/internal/NullSafeCopies.java
@@ -0,0 +1,39 @@
+/*
+ * 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.googlecloud.internal;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public final class NullSafeCopies {
+
+   public static <K, V> Map<K, V> copyOf(@Nullable Map<K, V> map) {
+      return map != null ? ImmutableMap.copyOf(map) : ImmutableMap.<K, V>of();
+   }
+
+   public static <E> List<E> copyOf(@Nullable List<E> list) {
+      return list != null ? ImmutableList.copyOf(list) : ImmutableList.<E>of();
+   }
+
+   private NullSafeCopies() {
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/main/java/org/jclouds/googlecloud/options/ListOptions.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/main/java/org/jclouds/googlecloud/options/ListOptions.java 
b/googlecloud/src/main/java/org/jclouds/googlecloud/options/ListOptions.java
new file mode 100644
index 0000000..a7ec97d
--- /dev/null
+++ b/googlecloud/src/main/java/org/jclouds/googlecloud/options/ListOptions.java
@@ -0,0 +1,30 @@
+/*
+ * 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.googlecloud.options;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+/** Base controls for listing resources in google cloud products. */
+public abstract class ListOptions extends BaseHttpRequestOptions {
+   /**  Sets Maximum count of results to be returned. Maximum value is 
product-specific. */
+   public ListOptions maxResults(Integer maxResults) {
+      this.queryParameters.put("maxResults", checkNotNull(maxResults, 
"maxResults").toString());
+      return this;
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/googlecloud/src/test/java/org/jclouds/googlecloud/internal/TestProperties.java
----------------------------------------------------------------------
diff --git 
a/googlecloud/src/test/java/org/jclouds/googlecloud/internal/TestProperties.java
 
b/googlecloud/src/test/java/org/jclouds/googlecloud/internal/TestProperties.java
new file mode 100644
index 0000000..32ea5cc
--- /dev/null
+++ 
b/googlecloud/src/test/java/org/jclouds/googlecloud/internal/TestProperties.java
@@ -0,0 +1,85 @@
+/*
+ * 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.googlecloud.internal;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Throwables.propagate;
+import static 
org.jclouds.googlecloud.config.GoogleCloudProperties.CREDENTIAL_TYPE;
+import static 
org.jclouds.googlecloud.config.GoogleCloudProperties.PROJECT_NAME;
+import static 
org.jclouds.oauth.v2.config.CredentialType.P12_PRIVATE_KEY_CREDENTIALS;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.jclouds.oauth.v2.config.CredentialType;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+
+/** Changes to this mandate changes to pom.xml and README.md */
+public final class TestProperties {
+
+   public static Properties apply(String provider, Properties props) {
+      setIfTestSystemPropertyPresent(props, PROJECT_NAME);
+      setIfTestSystemPropertyPresent(props, CREDENTIAL_TYPE);
+      if (props.containsKey(CREDENTIAL_TYPE)
+            && CredentialType.fromValue(props.getProperty(CREDENTIAL_TYPE)) == 
P12_PRIVATE_KEY_CREDENTIALS) {
+         setCredential(props, provider + ".credential");
+      }
+      return props;
+   }
+
+   // TODO: make BaseApiLiveTest.setIfTestSystemPropertyPresent static
+   private static String setIfTestSystemPropertyPresent(Properties overrides, 
String key) {
+      if (System.getProperties().containsKey("test." + key)) {
+         String val = System.getProperty("test." + key);
+         overrides.setProperty(key, val);
+         return val;
+      }
+      return null;
+   }
+
+   // TODO: move to jclouds-core
+   public static String setCredential(Properties overrides, String key) {
+      String val = null;
+      String credentialFromFile = null;
+      String testKey = "test." + key;
+
+      if (System.getProperties().containsKey(testKey)) {
+         val = System.getProperty(testKey);
+      }
+      checkNotNull(val,
+            String.format("the property %s must be set (pem private key file 
path or private key as a string)",
+                  testKey));
+
+      if (val.startsWith("-----BEGIN")) {
+         return val;
+      }
+
+      try {
+         credentialFromFile = Files.toString(new File(val), Charsets.UTF_8);
+      } catch (IOException e) {
+         throw propagate(e);
+      }
+      overrides.setProperty(key, credentialFromFile);
+      return credentialFromFile;
+   }
+
+   private TestProperties() {
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java
----------------------------------------------------------------------
diff --git a/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java 
b/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java
index ed512d3..e5ec5ec 100644
--- a/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java
+++ b/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java
@@ -55,6 +55,7 @@ public class OAuthTestUtils {
       return properties;
    }
 
+   // TODO: move to jclouds-core
    public static String setCredential(Properties overrides, String key) {
       String val = null;
       String credentialFromFile = null;

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f191c8fb/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b13f524..887351c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,6 +55,7 @@
 
   <modules>
     <module>oauth</module>
+    <module>googlecloud</module>
     <module>google-compute-engine</module>
     <module>google-cloud-storage</module>
   </modules>

Reply via email to