1616
1717package com .google .gcloud .storage .testing ;
1818
19- import com .google .common .collect .ImmutableMap ;
2019import com .google .gcloud .AuthCredentials ;
2120import com .google .gcloud .storage .BlobInfo ;
2221import com .google .gcloud .RetryParams ;
2322import com .google .gcloud .storage .Storage ;
2423import com .google .gcloud .storage .StorageException ;
2524import com .google .gcloud .storage .StorageOptions ;
26- import com .google .gcloud .storage .testing .RemoteGcsHelper .Option .KeyFromClasspath ;
2725
2826import java .io .FileInputStream ;
2927import java .io .FileNotFoundException ;
3028import java .io .InputStream ;
3129import java .io .IOException ;
32- import java .util .Map ;
3330import java .util .UUID ;
3431import java .util .concurrent .Callable ;
3532import java .util .concurrent .ExecutionException ;
@@ -134,29 +131,14 @@ public static RemoteGcsHelper create(String projectId, InputStream keyStream)
134131 *
135132 * @param projectId id of the project to be used for running the tests
136133 * @param keyPath path to the JSON key to be used for running the tests
137- * @param options creation options
138134 * @return A {@code RemoteGcsHelper} object for the provided options.
139135 * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if the file
140136 * pointed by {@code keyPath} does not exist
141137 */
142- public static RemoteGcsHelper create (String projectId , String keyPath , Option ... options )
138+ public static RemoteGcsHelper create (String projectId , String keyPath )
143139 throws GcsHelperException {
144- boolean keyFromClassPath = false ;
145- Map <Class <? extends Option >, Option > optionsMap = Option .asImmutableMap (options );
146- if (optionsMap .containsKey (KeyFromClasspath .class )) {
147- keyFromClassPath =
148- ((KeyFromClasspath ) optionsMap .get (KeyFromClasspath .class )).keyFromClasspath ();
149- }
150140 try {
151- InputStream keyFileStream ;
152- if (keyFromClassPath ) {
153- keyFileStream = RemoteGcsHelper .class .getResourceAsStream (keyPath );
154- if (keyFileStream == null ) {
155- throw new FileNotFoundException (keyPath + " not found in classpath" );
156- }
157- } else {
158- keyFileStream = new FileInputStream (keyPath );
159- }
141+ InputStream keyFileStream = new FileInputStream (keyPath );
160142 return create (projectId , keyFileStream );
161143 } catch (FileNotFoundException ex ) {
162144 if (log .isLoggable (Level .WARNING )) {
@@ -175,13 +157,12 @@ public static RemoteGcsHelper create(String projectId, String keyPath, Option...
175157 * Creates a {@code RemoteGcsHelper} object. Project id and path to JSON key are read from two
176158 * environment variables: {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY}.
177159 *
178- * @param options creation options
179160 * @return A {@code RemoteGcsHelper} object for the provided options.
180161 * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if environment
181162 * variables {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY} are not set or if
182163 * the file pointed by {@code GCLOUD_TESTS_KEY} does not exist
183164 */
184- public static RemoteGcsHelper create (Option ... options ) throws GcsHelperException {
165+ public static RemoteGcsHelper create () throws GcsHelperException {
185166 String projectId = System .getenv (PROJECT_ID_ENV_VAR );
186167 String keyPath = System .getenv (PRIVATE_KEY_ENV_VAR );
187168 if (projectId == null ) {
@@ -198,7 +179,7 @@ public static RemoteGcsHelper create(Option... options) throws GcsHelperExceptio
198179 }
199180 throw new GcsHelperException (message );
200181 }
201- return create (projectId , keyPath , options );
182+ return create (projectId , keyPath );
202183 }
203184
204185 private static class DeleteBucketTask implements Callable <Boolean > {
@@ -231,42 +212,6 @@ public Boolean call() throws Exception {
231212 }
232213 }
233214
234- public static abstract class Option implements java .io .Serializable {
235-
236- private static final long serialVersionUID = 8849118657896662369L ;
237-
238- public static final class KeyFromClasspath extends Option {
239-
240- private static final long serialVersionUID = -5506049413185246821L ;
241-
242- private final boolean keyFromClasspath ;
243-
244- public KeyFromClasspath (boolean keyFromClasspath ) {
245- this .keyFromClasspath = keyFromClasspath ;
246- }
247-
248- public boolean keyFromClasspath () {
249- return keyFromClasspath ;
250- }
251- }
252-
253- Option () {
254- // package protected
255- }
256-
257- public static KeyFromClasspath keyFromClassPath () {
258- return new KeyFromClasspath (true );
259- }
260-
261- static Map <Class <? extends Option >, Option > asImmutableMap (Option ... options ) {
262- ImmutableMap .Builder <Class <? extends Option >, Option > builder = ImmutableMap .builder ();
263- for (Option option : options ) {
264- builder .put (option .getClass (), option );
265- }
266- return builder .build ();
267- }
268- }
269-
270215 public static class GcsHelperException extends RuntimeException {
271216
272217 private static final long serialVersionUID = -7756074894502258736L ;
0 commit comments