Skip to content

Commit ce3c0bb

Browse files
committed
---
yaml --- r: 4207 b: refs/heads/gcs-nio c: 5fea95f h: refs/heads/master i: 4205: c883b99 4203: 1f25089 4199: 91728a9 4191: 83ba16d
1 parent da95623 commit ce3c0bb

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ refs/tags/v0.0.12: 2fd8066e891fb3dfea69b65f6bf6461db79342b9
1111
refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
14-
refs/heads/gcs-nio: 8df138b0aba5dbfa0a5b8dc07a1dc6541b4d2bac
14+
refs/heads/gcs-nio: 5fea95fcd9f7d98aa7ff682664686fa06321f07a
1515
refs/heads/logging-alpha: db5312bffa7fccac194f6a7feb8cc3066de16aff
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0

branches/gcs-nio/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.api.client.http.javanet.NetHttpTransport;
2828
import com.google.auth.http.HttpCredentialsAdapter;
2929
import com.google.common.collect.Iterables;
30+
import com.google.common.io.Files;
3031
import com.google.gcloud.spi.ServiceRpcFactory;
3132

3233
import java.io.BufferedReader;
@@ -42,6 +43,7 @@
4243
import java.lang.reflect.Method;
4344
import java.net.HttpURLConnection;
4445
import java.net.URL;
46+
import java.nio.charset.Charset;
4547
import java.util.Enumeration;
4648
import java.util.Locale;
4749
import java.util.Objects;
@@ -381,6 +383,18 @@ protected String defaultProject() {
381383
return projectId != null ? projectId : googleCloudProjectId();
382384
}
383385

386+
private static String activeGoogleCloudConfig(File configDir) {
387+
String activeGoogleCloudConfig = null;
388+
try {
389+
activeGoogleCloudConfig =
390+
Files.readFirstLine(new File(configDir, "active_config"), Charset.defaultCharset());
391+
} catch (IOException ex) {
392+
// ignore
393+
}
394+
// if reading active_config failed or the file is empty we try default
395+
return firstNonNull(activeGoogleCloudConfig, "default");
396+
}
397+
384398
protected static String googleCloudProjectId() {
385399
File configDir;
386400
if (System.getenv().containsKey("CLOUDSDK_CONFIG")) {
@@ -390,9 +404,10 @@ protected static String googleCloudProjectId() {
390404
} else {
391405
configDir = new File(System.getProperty("user.home"), ".config/gcloud");
392406
}
407+
String activeConfig = activeGoogleCloudConfig(configDir);
393408
FileReader fileReader = null;
394409
try {
395-
fileReader = new FileReader(new File(configDir, "configurations/config_default"));
410+
fileReader = new FileReader(new File(configDir, "configurations/config_" + activeConfig));
396411
} catch (FileNotFoundException newConfigFileNotFoundEx) {
397412
try {
398413
fileReader = new FileReader(new File(configDir, "properties"));

0 commit comments

Comments
 (0)