summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStas Negara <snegara@google.com>2015-05-06 14:49:42 -0700
committerStas Negara <snegara@google.com>2015-05-07 16:50:23 -0700
commite58e92dade0f641c11f9afc8b522b524a579a57d (patch)
tree20f3c159ef62b2ea9ed4f8db3cfbe0c521e2c87a
parente47a3c0bcffad3598258c70282aa1d71ff9746c9 (diff)
downloadtesting-e58e92dade0f641c11f9afc8b522b524a579a57d.tar.gz
Detect from an external source whether our plugin is ready.
Users will see the option to enable our plugin only when it is ready for the general public. Also, change capturing Throwable to Exception. Change-Id: If0ad0a8a60ecf4a3c3a2fe2c8d0816451ad25382
-rw-r--r--src/com/google/gct/testing/CloudConfigurationProviderImpl.java28
-rw-r--r--src/com/google/gct/testing/DebugConfigurationAction.java2
-rw-r--r--src/com/google/gct/testing/launcher/CloudAuthenticator.java8
3 files changed, 34 insertions, 4 deletions
diff --git a/src/com/google/gct/testing/CloudConfigurationProviderImpl.java b/src/com/google/gct/testing/CloudConfigurationProviderImpl.java
index 4fd28fa..4ca8a21 100644
--- a/src/com/google/gct/testing/CloudConfigurationProviderImpl.java
+++ b/src/com/google/gct/testing/CloudConfigurationProviderImpl.java
@@ -25,6 +25,7 @@ import com.google.api.client.util.Maps;
import com.google.api.client.util.Sets;
import com.google.api.services.storage.Storage;
import com.google.api.services.storage.model.Buckets;
+import com.google.api.services.storage.model.StorageObject;
import com.google.api.services.testing.model.AndroidDevice;
import com.google.api.services.testing.model.Device;
import com.google.api.services.testing.model.ResultStorage;
@@ -68,6 +69,7 @@ import java.util.*;
import static com.android.tools.idea.run.CloudConfiguration.Kind.MATRIX;
import static com.android.tools.idea.run.CloudConfiguration.Kind.SINGLE_DEVICE;
+import static com.google.gct.testing.launcher.CloudAuthenticator.getStorage;
import static com.google.gct.testing.launcher.CloudAuthenticator.getTest;
public class CloudConfigurationProviderImpl extends CloudConfigurationProvider {
@@ -252,8 +254,8 @@ public class CloudConfigurationProviderImpl extends CloudConfigurationProvider {
try {
Storage.Buckets.List listBuckets = CloudAuthenticator.getStorage().buckets().list(cloudProjectId);
buckets = listBuckets.execute();
- } catch (Throwable t) {
- message = t.getMessage();
+ } catch (Exception e) {
+ message = e.getMessage();
// ignore
} finally {
if (buckets == null) {
@@ -383,7 +385,7 @@ public class CloudConfigurationProviderImpl extends CloudConfigurationProvider {
public Icon getCloudDeviceIcon() {
try {
return new ImageIcon(ImageIO.read(CloudConfigurationProviderImpl.class.getResourceAsStream("CloudDevice.png")));
- } catch (Throwable e) {
+ } catch (Exception e) {
return null;
}
}
@@ -459,6 +461,26 @@ public class CloudConfigurationProviderImpl extends CloudConfigurationProvider {
return new DefaultExecutionResult(console, runningState.getProcessHandler());
}
+ @Override
+ protected boolean canBeEnabled() {
+ final String publicBucketName = "cloud-testing-plugin-enablement";
+ final String triggerFileName = "ENABLED";
+ try {
+ Storage.Objects.List objects = CloudAuthenticator.getPublicStorage().objects().list(publicBucketName);
+ List<StorageObject> storageObjects = objects.execute().getItems();
+ if (storageObjects != null) {
+ for (StorageObject storageObject : storageObjects) {
+ if (triggerFileName.equals(storageObject.getName())) {
+ return true;
+ }
+ }
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ return false;
+ }
+
private void performTestsInCloud(final CloudConfigurationImpl cloudTestingConfiguration, final String cloudProjectId,
final AndroidRunningState runningState, final GoogleCloudTestingResultParser cloudResultParser,
final CloudMatrixExecutionCancellator matrixExecutionCancellator) {
diff --git a/src/com/google/gct/testing/DebugConfigurationAction.java b/src/com/google/gct/testing/DebugConfigurationAction.java
index 3b43cde..901a4ee 100644
--- a/src/com/google/gct/testing/DebugConfigurationAction.java
+++ b/src/com/google/gct/testing/DebugConfigurationAction.java
@@ -52,7 +52,7 @@ public class DebugConfigurationAction extends AnAction {
try {
ICON = new ImageIcon(ImageIO.read(DebugConfigurationAction.class.getResourceAsStream("CloudDebug.png")));
}
- catch (Throwable e) { // If something goes wrong, just use the original debug icon.
+ catch (Exception e) { // If something goes wrong, just use the original debug icon.
ICON = AllIcons.General.Debug;
}
}
diff --git a/src/com/google/gct/testing/launcher/CloudAuthenticator.java b/src/com/google/gct/testing/launcher/CloudAuthenticator.java
index c1f2276..9321345 100644
--- a/src/com/google/gct/testing/launcher/CloudAuthenticator.java
+++ b/src/com/google/gct/testing/launcher/CloudAuthenticator.java
@@ -42,6 +42,14 @@ public class CloudAuthenticator {
private static long lastDiscoveryServiceInvocationTimestamp = -1;
+ public static Storage getPublicStorage() {
+ if (httpTransport == null) {
+ httpTransport = createHttpTransport();
+ }
+ // A storage accessible to anyone without authentication and authorization (null credential).
+ return new Storage.Builder(httpTransport, JacksonFactory.getDefaultInstance(), null).build();
+ }
+
public static Storage getStorage() {
prepareCredential();
if (storage == null) {